From c99e119321c9bad3a7059314eb2354d47a91d2c3 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Fri, 14 Aug 2026 22:15:20 +0100 Subject: [PATCH 1/3] quote generator --- Sprint-3/quote-generator/quotes.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Sprint-3/quote-generator/quotes.js b/Sprint-3/quote-generator/quotes.js index 4a4d04b72..517b50fec 100644 --- a/Sprint-3/quote-generator/quotes.js +++ b/Sprint-3/quote-generator/quotes.js @@ -22,6 +22,7 @@ function pickFromArray(choices) { // A list of quotes you can use in your app. // DO NOT modify this array, otherwise the tests may break! + const quotes = [ { quote: "Life isn't about getting and having, it's about giving and being.", @@ -489,5 +490,20 @@ const quotes = [ author: "Zig Ziglar", }, ]; +function displayQuote() { + const quoteElement = document.getElementById("quote"); + const authorElement = document.getElementById("author"); + + const randomQuote = pickFromArray(quotes); + + quoteElement.innerText = randomQuote.quote; + authorElement.innerText = randomQuote.author; +} + +const newQuoteButton = document.getElementById("new-quote"); + +newQuoteButton.addEventListener("click", displayQuote); + +displayQuote(); // call pickFromArray with the quotes array to check you get a random quote From 6e37b5a79a696072626f9a2345424a4a893789a8 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Fri, 14 Aug 2026 22:15:34 +0100 Subject: [PATCH 2/3] slide show --- Sprint-3/slideshow/slideshow.js | 64 +++++++++++++++++++++++++++++-- Sprint-3/todo-list/todos.mjs | 6 +-- Sprint-3/todo-list/todos.test.mjs | 17 +++----- 3 files changed, 69 insertions(+), 18 deletions(-) diff --git a/Sprint-3/slideshow/slideshow.js b/Sprint-3/slideshow/slideshow.js index 063ceefb5..10fd18515 100644 --- a/Sprint-3/slideshow/slideshow.js +++ b/Sprint-3/slideshow/slideshow.js @@ -1,8 +1,64 @@ const images = [ - "./assets/cute-cat-a.png", - "./assets/cute-cat-b.jpg", - "./assets/cute-cat-c.jpg", + "./assets/cute-cat-a.png", + "./assets/cute-cat-b.jpg", + "./assets/cute-cat-c.jpg", ]; +let currentIndex = 0; +let timer = null; -// Write your code here \ No newline at end of file +const image = document.querySelector("#carousel-img"); +const forwardBtn = document.querySelector("#forward-btn"); +const backwardBtn = document.querySelector("#backward-btn"); +const autoForwardBtn = document.querySelector("#auto-forward"); +const autoBackBtn = document.querySelector("#auto-backward"); +const stopBtn = document.querySelector("#stop"); + +// Display the current image +function displayImage() { + image.src = images[currentIndex]; +} + +// Move forward +function moveForward() { + currentIndex = (currentIndex + 1) % images.length; + displayImage(); +} + +// Move backward +function moveBackward() { + currentIndex = (currentIndex - 1 + images.length) % images.length; + displayImage(); +} + +// Manual controls +forwardBtn.addEventListener("click", moveForward); +backwardBtn.addEventListener("click", moveBackward); + +// Automatic forward +autoForwardBtn.addEventListener("click", () => { + timer = setInterval(moveForward, 2000); + + autoForwardBtn.disabled = true; + autoBackBtn.disabled = true; +}); + +// Automatic backward +autoBackBtn.addEventListener("click", () => { + timer = setInterval(moveBackward, 2000); + + autoForwardBtn.disabled = true; + autoBackBtn.disabled = true; +}); + +// Stop automatic movement +stopBtn.addEventListener("click", () => { + clearInterval(timer); + timer = null; + + autoForwardBtn.disabled = false; + autoBackBtn.disabled = false; +}); + +// Show first image when page loads +displayImage(); diff --git a/Sprint-3/todo-list/todos.mjs b/Sprint-3/todo-list/todos.mjs index f17ab6a25..1e25e194c 100644 --- a/Sprint-3/todo-list/todos.mjs +++ b/Sprint-3/todo-list/todos.mjs @@ -16,14 +16,14 @@ export function addTask(todos, task, completed = false) { // Delete todos[taskIndex] if it exists export function deleteTask(todos, taskIndex) { - if (todos[taskIndex]) { + if (taskIndex >= 0 && taskIndex < todos.length) { todos.splice(taskIndex, 1); } } // Toggle the "completed" property of todos[taskIndex] if the task exists. export function toggleCompletedOnTask(todos, taskIndex) { - if (todos[taskIndex]) { + if (taskIndex >= 0 && taskIndex < todos.length) { todos[taskIndex].completed = !todos[taskIndex].completed; } -} \ No newline at end of file +} diff --git a/Sprint-3/todo-list/todos.test.mjs b/Sprint-3/todo-list/todos.test.mjs index bae7ae491..a00b82b71 100644 --- a/Sprint-3/todo-list/todos.test.mjs +++ b/Sprint-3/todo-list/todos.test.mjs @@ -13,7 +13,7 @@ function createMockTodos() { { task: "Task 1 description", completed: true }, { task: "Task 2 description", completed: false }, { task: "Task 3 description", completed: true }, - { task: "Task 4 description", completed: false }, + { task: "Task 4 description", completed: false }, ]; } @@ -29,7 +29,6 @@ describe("addTask()", () => { }); test("Should append a new task to the end of a ToDo list", () => { - const todos = createMockTodos(); const lengthBeforeAddition = todos.length; Todos.addTask(todos, theTask.task, theTask.completed); @@ -42,7 +41,6 @@ describe("addTask()", () => { }); describe("deleteTask()", () => { - test("Delete the first task", () => { const todos = createMockTodos(); const todosBeforeDeletion = createMockTodos(); @@ -53,7 +51,7 @@ describe("deleteTask()", () => { expect(todos[0]).toEqual(todosBeforeDeletion[1]); expect(todos[1]).toEqual(todosBeforeDeletion[2]); - expect(todos[2]).toEqual(todosBeforeDeletion[3]); + expect(todos[2]).toEqual(todosBeforeDeletion[3]); }); test("Delete the second task (a middle task)", () => { @@ -66,7 +64,7 @@ describe("deleteTask()", () => { expect(todos[0]).toEqual(todosBeforeDeletion[0]); expect(todos[1]).toEqual(todosBeforeDeletion[2]); - expect(todos[2]).toEqual(todosBeforeDeletion[3]); + expect(todos[2]).toEqual(todosBeforeDeletion[3]); }); test("Delete the last task", () => { @@ -79,7 +77,7 @@ describe("deleteTask()", () => { expect(todos[0]).toEqual(todosBeforeDeletion[0]); expect(todos[1]).toEqual(todosBeforeDeletion[1]); - expect(todos[2]).toEqual(todosBeforeDeletion[2]); + expect(todos[2]).toEqual(todosBeforeDeletion[2]); }); test("Delete a non-existing task", () => { @@ -94,7 +92,6 @@ describe("deleteTask()", () => { }); describe("toggleCompletedOnTask()", () => { - test("Expect the 'completed' property to toggle on an existing task", () => { const todos = createMockTodos(); const taskIndex = 1; @@ -111,13 +108,12 @@ describe("toggleCompletedOnTask()", () => { const todos = createMockTodos(); const todosBeforeToggle = createMockTodos(); Todos.toggleCompletedOnTask(todos, 1); - - expect(todos[0]).toEqual(todosBeforeToggle[0]); + + expect(todos[0]).toEqual(todosBeforeToggle[0]); expect(todos[2]).toEqual(todosBeforeToggle[2]); expect(todos[3]).toEqual(todosBeforeToggle[3]); }); - test("Expect no change when toggling on a non-existing task", () => { const todos = createMockTodos(); const todosBeforeToggle = createMockTodos(); @@ -129,4 +125,3 @@ describe("toggleCompletedOnTask()", () => { expect(todos).toEqual(todosBeforeToggle); }); }); - From aced6fc202d532bdaf5edd62d554159e1661a200 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Sat, 15 Aug 2026 14:22:35 +0100 Subject: [PATCH 3/3] reinstate files --- Sprint-3/quote-generator/quotes.js | 16 -------- Sprint-3/slideshow/slideshow.js | 64 ++---------------------------- 2 files changed, 4 insertions(+), 76 deletions(-) diff --git a/Sprint-3/quote-generator/quotes.js b/Sprint-3/quote-generator/quotes.js index 517b50fec..4a4d04b72 100644 --- a/Sprint-3/quote-generator/quotes.js +++ b/Sprint-3/quote-generator/quotes.js @@ -22,7 +22,6 @@ function pickFromArray(choices) { // A list of quotes you can use in your app. // DO NOT modify this array, otherwise the tests may break! - const quotes = [ { quote: "Life isn't about getting and having, it's about giving and being.", @@ -490,20 +489,5 @@ const quotes = [ author: "Zig Ziglar", }, ]; -function displayQuote() { - const quoteElement = document.getElementById("quote"); - const authorElement = document.getElementById("author"); - - const randomQuote = pickFromArray(quotes); - - quoteElement.innerText = randomQuote.quote; - authorElement.innerText = randomQuote.author; -} - -const newQuoteButton = document.getElementById("new-quote"); - -newQuoteButton.addEventListener("click", displayQuote); - -displayQuote(); // call pickFromArray with the quotes array to check you get a random quote diff --git a/Sprint-3/slideshow/slideshow.js b/Sprint-3/slideshow/slideshow.js index 10fd18515..063ceefb5 100644 --- a/Sprint-3/slideshow/slideshow.js +++ b/Sprint-3/slideshow/slideshow.js @@ -1,64 +1,8 @@ const images = [ - "./assets/cute-cat-a.png", - "./assets/cute-cat-b.jpg", - "./assets/cute-cat-c.jpg", + "./assets/cute-cat-a.png", + "./assets/cute-cat-b.jpg", + "./assets/cute-cat-c.jpg", ]; -let currentIndex = 0; -let timer = null; -const image = document.querySelector("#carousel-img"); -const forwardBtn = document.querySelector("#forward-btn"); -const backwardBtn = document.querySelector("#backward-btn"); -const autoForwardBtn = document.querySelector("#auto-forward"); -const autoBackBtn = document.querySelector("#auto-backward"); -const stopBtn = document.querySelector("#stop"); - -// Display the current image -function displayImage() { - image.src = images[currentIndex]; -} - -// Move forward -function moveForward() { - currentIndex = (currentIndex + 1) % images.length; - displayImage(); -} - -// Move backward -function moveBackward() { - currentIndex = (currentIndex - 1 + images.length) % images.length; - displayImage(); -} - -// Manual controls -forwardBtn.addEventListener("click", moveForward); -backwardBtn.addEventListener("click", moveBackward); - -// Automatic forward -autoForwardBtn.addEventListener("click", () => { - timer = setInterval(moveForward, 2000); - - autoForwardBtn.disabled = true; - autoBackBtn.disabled = true; -}); - -// Automatic backward -autoBackBtn.addEventListener("click", () => { - timer = setInterval(moveBackward, 2000); - - autoForwardBtn.disabled = true; - autoBackBtn.disabled = true; -}); - -// Stop automatic movement -stopBtn.addEventListener("click", () => { - clearInterval(timer); - timer = null; - - autoForwardBtn.disabled = false; - autoBackBtn.disabled = false; -}); - -// Show first image when page loads -displayImage(); +// Write your code here \ No newline at end of file