From 5007c4b2e7454bed90a8cb18e7332329a4f67932 Mon Sep 17 00:00:00 2001 From: asaniDev Date: Thu, 30 Oct 2025 01:35:50 +0000 Subject: [PATCH 01/14] added all tests to test, started mean.js but not finished --- prep/mean.js | 18 ++++++++++++++++++ prep/mean.test.js | 22 ++++++++++++++++++++++ prep/package.json | 16 ++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 prep/mean.js create mode 100644 prep/mean.test.js create mode 100644 prep/package.json diff --git a/prep/mean.js b/prep/mean.js new file mode 100644 index 000000000..31f463f9c --- /dev/null +++ b/prep/mean.js @@ -0,0 +1,18 @@ +//a data structure is used to group data together. it is a collection of data which has functions which allow you to access and manipulate the data. +//an array is a zero indexed collection of data that holds data in an ordered list. +function calculateMean(list) { + let total = 0; + + for (const item of list) { + total += item; + } +} + +function calculateMedian(list) { + const middleIndex = Math.floor(list.length / 2); + const median = list.splice(middleIndex, 1)[0]; + + return median; +} + +calculateMean([10, 20, 30, 40, 50]); diff --git a/prep/mean.test.js b/prep/mean.test.js new file mode 100644 index 000000000..386732522 --- /dev/null +++ b/prep/mean.test.js @@ -0,0 +1,22 @@ +test("calculates the mean of a list of numbers", () => { + const list = [3, 50, 7]; + const currentOutput = calculateMean(list); + const targetOutput = 20; + + expect(currentOutput).toEqual(targetOutput); +}); + +test("calculates the median of a list of odd length", () => { + const list = [10, 20, 30, 50, 60]; + const currentOutput = calculateMedian(list); + const targetOutput = 30; + + expect(currentOutput).toEqual(targetOutput); +}); + +test("doesn't modify the input", () => { + const list = [1, 2, 3]; + calculateMedian(list); + + expect(list).toEqual([1, 2, 3]); // Note that the toEqual matcher checks the values inside arrays when comparing them - it doesn't use `===` on the arrays, we know that would always evaluate to false. +}); diff --git a/prep/package.json b/prep/package.json new file mode 100644 index 000000000..2301e1638 --- /dev/null +++ b/prep/package.json @@ -0,0 +1,16 @@ +{ + "name": "prep", + "version": "1.0.0", + "description": "", + "main": "mean.js", + "scripts": { + "test": "jest" + }, + "keywords": [], + "author": "", + "license": "ISC", + "type": "commonjs", + "devDependencies": { + "jest": "^30.2.0" + } +} From f21c96e6e26ba3ce80b0bf42afe82a6ec0937e1b Mon Sep 17 00:00:00 2001 From: asaniDev Date: Sat, 15 Nov 2025 13:53:39 +0000 Subject: [PATCH 02/14] predicted the result of each file before fixing them --- Sprint-2/debug/address.js | 4 +++- Sprint-2/debug/author.js | 4 +++- Sprint-2/debug/recipe.js | 10 +++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Sprint-2/debug/address.js b/Sprint-2/debug/address.js index 940a6af83..41ce8e624 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -1,8 +1,10 @@ // Predict and explain first... +//the original code is using the wrong notation to access our object this will return undefined as we do not have a 0 property. // This code should log out the houseNumber from the address object // but it isn't working... // Fix anything that isn't working +//fixed it by puting "houseNumber" in the square brackets. const address = { houseNumber: 42, @@ -12,4 +14,4 @@ const address = { postcode: "XYZ 123", }; -console.log(`My house number is ${address[0]}`); +console.log(`My house number is ${address["houseNumber"]}`); diff --git a/Sprint-2/debug/author.js b/Sprint-2/debug/author.js index 8c2125977..a78491d62 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -1,7 +1,9 @@ // Predict and explain first... +//the method for of is an array method and it would be looking for an indexed list of items rather than a key value pair so an error will be thrown since we are using an object. // This program attempts to log out all the property values in the object. // But it isn't working. Explain why first and then fix the problem +//i can fix this by changing for ... of to for ... in. const author = { firstName: "Zadie", @@ -11,6 +13,6 @@ const author = { alive: true, }; -for (const value of author) { +for (const value in author) { console.log(value); } diff --git a/Sprint-2/debug/recipe.js b/Sprint-2/debug/recipe.js index 6cbdd22cd..47cbc6ba1 100644 --- a/Sprint-2/debug/recipe.js +++ b/Sprint-2/debug/recipe.js @@ -1,8 +1,10 @@ // Predict and explain first... +//it will display the title and number of people it serves on one line then the whole recipe on the next line // This program should log out the title, how many it serves and the ingredients. // Each ingredient should be logged on a new line // How can you fix it? +//by using the string literal to ensure multiple lines, then having the title on the first line, the number served on the next line and ingredients on the third line. using the dot notation to access the properties needed. const recipe = { title: "bruschetta", @@ -10,6 +12,8 @@ const recipe = { ingredients: ["olive oil", "tomatoes", "salt", "pepper"], }; -console.log(`${recipe.title} serves ${recipe.serves} - ingredients: -${recipe}`); +console.log(`${recipe.title} serves ${recipe.serves} + ingredients: ${recipe.ingredients[0]} + ${recipe.ingredients[1]} + ${recipe.ingredients[2]} + ${recipe.ingredients[3]}`); From b058970b50ab73fadd1a5b531babf5dc84ec83ff Mon Sep 17 00:00:00 2001 From: asaniDev Date: Sat, 15 Nov 2025 13:54:38 +0000 Subject: [PATCH 03/14] installed dependencies --- Sprint-2/package-lock.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-2/package-lock.json b/Sprint-2/package-lock.json index 9b4c725d6..ceda7296e 100644 --- a/Sprint-2/package-lock.json +++ b/Sprint-2/package-lock.json @@ -56,6 +56,7 @@ "integrity": "sha512-Oixnb+DzmRT30qu9d3tJSQkxuygWm32DFykT4bRoORPa9hZ/L4KhVB/XiRm6KG+roIEM7DBQlmg27kw2HZkdZg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@ampproject/remapping": "^2.2.0", "@babel/code-frame": "^7.25.7", @@ -1368,6 +1369,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "caniuse-lite": "^1.0.30001663", "electron-to-chromium": "^1.5.28", From b63c6de42d9bc9b7336434491be58650ab6d815f Mon Sep 17 00:00:00 2001 From: asaniDev Date: Sun, 23 Nov 2025 01:01:17 +0000 Subject: [PATCH 04/14] made up tests and then created functions to pass the required tests in implement folder --- Sprint-2/implement/contains.js | 33 +++++++++++++++++++++- Sprint-2/implement/contains.test.js | 11 +++++++- Sprint-2/implement/lookup.js | 17 +++++++++++- Sprint-2/implement/lookup.test.js | 21 +++++++++++++- Sprint-2/implement/querystring.js | 36 +++++++++++++++++++++--- Sprint-2/implement/querystring.test.js | 24 ++++++++++++++-- Sprint-2/implement/tally.js | 38 +++++++++++++++++++++++++- Sprint-2/implement/tally.test.js | 17 +++++++++++- 8 files changed, 185 insertions(+), 12 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index cd779308a..12b9231c3 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,3 +1,34 @@ -function contains() {} +function contains(checkObj, checkProp) { + if ( + typeof checkObj === "object" && + checkObj !== null && + !Array.isArray(checkObj) + ) { + const checkKeys = Object.keys(checkObj); + let isProperty = false; + + if (checkKeys.length === 0) { + return false; + } + + if (Object.hasOwn(checkObj, checkProp)) { + return true; + } else { + for (let key of checkKeys) { + if (key === checkProp) { + isProperty = true; + } + } + + if (isProperty === false) { + return false; + } + } + } else { + throw new Error("error invalid parameter please provide an object"); + } +} + +contains({ d: "me" }, 4); module.exports = contains; diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 326bdb1f2..80a49f8cd 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -20,16 +20,25 @@ as the object doesn't contains a key of 'c' // Given an empty object // When passed to contains // Then it should return false -test.todo("contains on empty object returns false"); +test("contains on empty object returns false", () => + expect(contains({}, "a")).toBe(false)); // Given an object with properties // When passed to contains with an existing property name // Then it should return true +test("returns true when an object contains a property that matches the one passed to contains", () => + expect(contains({ area: "Manchester" }, "area")).toBe(true)); // Given an object with properties // When passed to contains with a non-existent property name // Then it should return false +test("returns false when an object with properties is passed to contains with a non-existent property name", () => + expect(contains({ area: "Manchester" }, "town")).toBe(false)); // Given invalid parameters like an array // When passed to contains // Then it should return false or throw an error +test("should throw an error when when an invalid parameter like an array is passed to contains", () => + expect(() => contains([1, 4], 4)).toThrow( + "error invalid parameter please provide an object" + )); diff --git a/Sprint-2/implement/lookup.js b/Sprint-2/implement/lookup.js index a6746e07f..dacb9fc31 100644 --- a/Sprint-2/implement/lookup.js +++ b/Sprint-2/implement/lookup.js @@ -1,5 +1,20 @@ -function createLookup() { +function createLookup(inputArray) { // implementation here + const returnObject = {}; + + if (Array.isArray(inputArray)) { + if (inputArray.length === 0) { + return "passed array was empty, no values to display"; + } + + for (let item of inputArray) { + returnObject[item[0]] = item[1]; + } + + return returnObject; + } else { + throw new Error("error incorrect parameter passed please provide an array"); + } } module.exports = createLookup; diff --git a/Sprint-2/implement/lookup.test.js b/Sprint-2/implement/lookup.test.js index 547e06c5a..7c5fd6a40 100644 --- a/Sprint-2/implement/lookup.test.js +++ b/Sprint-2/implement/lookup.test.js @@ -1,6 +1,25 @@ const createLookup = require("./lookup.js"); -test.todo("creates a country currency code lookup for multiple codes"); +test("creates a country currency code lookup for multiple codes", () => { + expect( + createLookup([ + ["US", "USD"], + ["CA", "CAD"], + ["MW", "MWK"], + ["ZW", "ZWD"], + ]) + ).toEqual({ US: "USD", CA: "CAD", MW: "MWK", ZW: "ZWD" }); +}); + +test("if passed an empty array , should print a message telling user array is empty", () => { + expect(createLookup([])).toBe("passed array was empty, no values to display"); +}); + +test("if passed parameter which is not an array throw an error", () => { + expect(() => createLookup("US, USD")).toThrow( + "error incorrect parameter passed please provide an array" + ); +}); /* diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index 45ec4e5f3..8bd59028e 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -3,14 +3,42 @@ function parseQueryString(queryString) { if (queryString.length === 0) { return queryParams; } - const keyValuePairs = queryString.split("&"); - for (const pair of keyValuePairs) { - const [key, value] = pair.split("="); - queryParams[key] = value; + if (queryString.includes("&")) { + const keyValuePairs = queryString.split("&"); + + for (const pair of keyValuePairs) { + let countMatch = 0; + + if (pair.includes("=")) { + const equalSignIndex = pair.indexOf("="); + + queryParams[pair.slice(0, equalSignIndex)] = pair.slice( + equalSignIndex + 1 + ); + } else { + throw new Error( + "error invalid format string, no = to separate key value pairs" + ); + } + } + } + + if (queryString.includes("=")) { + const equalSignIndex = queryString.indexOf("="); + + queryParams[queryString.slice(0, equalSignIndex)] = queryString.slice( + equalSignIndex + 1 + ); + } else { + throw new Error( + "error invalid format string, no = to separate key value pairs" + ); } return queryParams; } +console.log(`with ${parseQueryString("equation=x=y+1")}`); + module.exports = parseQueryString; diff --git a/Sprint-2/implement/querystring.test.js b/Sprint-2/implement/querystring.test.js index 3e218b789..7bdf55cd3 100644 --- a/Sprint-2/implement/querystring.test.js +++ b/Sprint-2/implement/querystring.test.js @@ -3,10 +3,30 @@ // Below is one test case for an edge case the implementation doesn't handle well. // Fix the implementation for this test, and try to think of as many other edge cases as possible - write tests and fix those too. -const parseQueryString = require("./querystring.js") +const parseQueryString = require("./querystring.js"); + +test("parseQueryString receives an empty string", () => { + expect(parseQueryString("")).toEqual({}); +}); test("parses querystring values containing =", () => { expect(parseQueryString("equation=x=y+1")).toEqual({ - "equation": "x=y+1", + equation: "x=y+1", }); }); + +test("if our function is passed only one key - value pair", () => { + expect(parseQueryString("color=brown")).toEqual({ color: "brown" }); +}); + +test("parses querystring without an =, it should throw an error", () => { + expect(() => parseQueryString("colorisequaltobrown")).toThrow( + "error invalid format string, no = to separate key value pairs" + ); +}); + +test("if our function is passed only one string but there is no =", () => { + expect(parseQueryString("color,brown")).toEqual( + "error invalid format string, no = to separate key value pair" + ); +}); diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index f47321812..cbdd2aecc 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -1,3 +1,39 @@ -function tally() {} +function tally(inputArray) { + if (Array.isArray(inputArray)) { + if (inputArray.length === 0) { + return {}; + } + + let itemCount = 0; + const tallyObject = {}; + let n = 0; + + while (inputArray.length > 0) { + const tempArray = []; + let i = 0; + let currentArrayItem = inputArray[0]; + + while (i < inputArray.length) { + if (currentArrayItem === inputArray[i]) { + itemCount++; + tempArray.push(inputArray.splice(i, 1)); + i--; + } + + i++; + } + + if (tempArray.length > 0) { + tallyObject[tempArray[0]] = tempArray.length; + } + } + console.log(`the new array and the new object ${tallyObject}`); + return tallyObject; + } else { + throw new Error("error invalid input passed, please provide an array"); + } +} + +console.log(`new object is ${tally(["a", "a", "b", "c", "c", "d", "a"])}`); module.exports = tally; diff --git a/Sprint-2/implement/tally.test.js b/Sprint-2/implement/tally.test.js index 2ceffa8dd..afc6315aa 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -23,12 +23,27 @@ const tally = require("./tally.js"); // Given an empty array // When passed to tally // Then it should return an empty object -test.todo("tally on an empty array returns an empty object"); +test("tally on an empty array returns an empty object", () => { + expect(tally([])).toEqual({}); +}); // Given an array with duplicate items // When passed to tally // Then it should return counts for each unique item +test("given an array with duplicate items it should return counts for each unique item ", () => { + expect(tally(["a", "a", "b", "c", "c", "d", "a"])).toEqual({ + a: 3, + b: 1, + c: 2, + d: 1, + }); +}); // Given an invalid input like a string // When passed to tally // Then it should throw an error +test("should throw an error when tally is passed an invalid input like a string", () => { + expect(() => tally("b,b,c,d,e,e,f")).toThrow( + "error invalid input passed, please provide an array" + ); +}); From e17bf3024c0beb907faf24b371e3997fec46f2aa Mon Sep 17 00:00:00 2001 From: asaniDev Date: Sat, 29 Nov 2025 16:08:23 +0000 Subject: [PATCH 05/14] fixed invert function,answered questions and added tests to check it works as expected --- Sprint-2/interpret/invert.js | 37 +++++++++++++++++++++++++++++-- Sprint-2/interpret/invert.test.js | 31 ++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 Sprint-2/interpret/invert.test.js diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index bb353fb1f..0c3bab967 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -9,21 +9,54 @@ function invert(obj) { const invertedObj = {}; - for (const [key, value] of Object.entries(obj)) { - invertedObj.key = value; + if (Object.prototype.toString.call(obj) === "[object Object]") { + for (const [key, value] of Object.entries(obj)) { + invertedObj[value] = key; + } + } else { + throw new Error("error invalid input entered, expecting an object"); } return invertedObj; } +module.exports = invert; + +console.log( + `the return value when invert is called with ${invert({ + cars: { toyota: 2, bmw: 1, benz: 4 }, + })}` +); + +/* +for (const property in obj) { + if (typeof obj[property] !== "string") { + throw new Error( + "error invalid input entered, expecting an object to have only strings as values" + ); + } else { + + } + } + +*/ + // a) What is the current return value when invert is called with { a : 1 } +//it returns a string describing the object. // b) What is the current return value when invert is called with { a: 1, b: 2 } +//it aso returns a string describing the object. // c) What is the target return value when invert is called with {a : 1, b: 2} +//the target return value is {"1": "a", "2": "b"}. // c) What does Object.entries return? Why is it needed in this program? +//it returns an array made up of arrays of the original objects key - value pairs. +//it allows us to unpack the contents of the object into an array which can then be used to create the new object // d) Explain why the current return value is different from the target output +//because we used dot notation to assign a value to our key, this creates a property called key +//and assigns it a value. we want our key to get its name from a variable so we need to use bracket notation. // e) Fix the implementation of invert (and write tests to prove it's fixed!) +//we can fix it by using invertedObj[value] = key. diff --git a/Sprint-2/interpret/invert.test.js b/Sprint-2/interpret/invert.test.js new file mode 100644 index 000000000..7ce178b17 --- /dev/null +++ b/Sprint-2/interpret/invert.test.js @@ -0,0 +1,31 @@ +const invert = require("./invert.js"); + +describe("tests to see if invert function swaps around the keys and values in a given object", () => { + test("if invert is passed a value which is not an object, it should throw an error", () => { + expect(() => + invert([ + ["x", 10], + ["y", 20], + ]) + ).toThrow("error invalid input entered, expecting an object"); + }); + + test("if we are passed an empty object we should return an empty object", () => { + expect(invert({})).toEqual({}); + }); + + test("given an object with key value pairs, it should swap the keys and values in the object", () => { + expect(invert({ x: 10, y: 20 })).toEqual({ 10: "x", 20: "y" }); + expect( + invert({ city: "Birmingham", population: "345908", boroughs: "20" }) + ).toEqual({ Birmingham: "city", 345908: "population", 20: "boroughs" }); + }); +}); + +/* +test("if invert is passed an object which has an array or object as one of its values, it should throw an error", () => { + expect(() => invert({ cars: { toyota: 2, bmw: 1, benz: 4 } })).toThrow( + "error invalid input entered, expecting an object to have only strings as values" + ); + }); +*/ From 8196fd629468c3d53444ca230796d68075382e07 Mon Sep 17 00:00:00 2001 From: asaniDev Date: Mon, 8 Dec 2025 02:34:45 +0000 Subject: [PATCH 06/14] made alarm clock countdown from user input number and alarm sound when it reaches 0 --- Sprint-3/alarmclock/alarmclock.js | 70 ++++++++++++++++++++++++++++++- Sprint-3/alarmclock/index.html | 2 +- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..f24ffdc9a 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,44 @@ -function setAlarm() {} +let inputTime = 0; +let timer = null; + +function setAlarm() { + inputTime = Number(document.querySelector("#alarmSet").value); + + if (Number.isInteger(inputTime) && !isNaN(inputTime) && inputTime >= 0) { + if (inputTime === 10) { + } + displayTime(inputTime); + if (timer) clearInterval(timer); + timer = setInterval(countDown, 1000); + } +} + +function displayTime(totalTime) { + const seconds = totalTime % 60; + const minutes = (totalTime - seconds) / 60; + const timeLeft = document.querySelector("#timeRemaining"); + timeLeft.innerText = `Time Remaining: ${minutes + .toString() + .padStart(2, 0)}:${seconds.toString().padStart(2, 0)}`; +} + +function countDown() { + inputTime--; + if (inputTime >= 0) { + displayTime(inputTime); + } + + if (inputTime === 0) { + playAlarm(); + clearInterval(timer); + timer = null; + } +} +/* +the the value for time remaining +check its a valid time (greater than 00:00) +decrease value of time remaining by 1 sec for each sec that passes +*/ // DO NOT EDIT BELOW HERE @@ -23,3 +63,31 @@ function pauseAlarm() { } window.onload = setup; + +/* +Given the user has entered a number in the input field When the user clicks the “Set Alarm” button Then the “Time Remaining” title should update to show the entered number in mm:ss format + take value from in input field and store it in a variable inputTime + check inputTime value is within the accepted range? + take variable inputTime and display it in time remaining section + + +Given the alarm is set with a valid time When one second passes Then the “Time Remaining” title should decrement by 1 second + the the value for time remaining + check its a valid time (greater than 00:00) + decrease value of time remaining by 1 sec for each sec that passes + +Given the alarm is set with a time of 00:00 When the timer reaches 00:00 Then the alarm sound should play continuously + check time remaining, if it is equal to 00:00 then sound alarm + + +Given the alarm sound is currently playing When the user clicks the “Stop Alarm” button Then the alarm sound should stop playing + check if stop alarm button has been pressed + if true then check if alarm sound is playing then stop alarm sound if true + +Given the alarm is set with a time of 00:10 When the timer reaches 00:00 Then the background color should change And the alarm sound should play + if inputTime is 00:10 and timer reaches 0 the change background color + play alarm sound + +Given the user has not set an alarm When the page first loads Then the “Time Remaining” title should show 00:00 And no alarm sound should play +when page loads time remaining should 0 and no alarm sound should play +*/ diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..4a91379d3 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Alarm Clock App
From 29cacc9c546d725d6baf2b5fd5d5152f12731ceb Mon Sep 17 00:00:00 2001 From: asaniDev Date: Mon, 8 Dec 2025 02:59:38 +0000 Subject: [PATCH 07/14] made sure when input time is 0, alarm still works and added background colour for timer starting at 10 --- Sprint-3/alarmclock/alarmclock.js | 16 ++++++++++++++++ Sprint-3/alarmclock/style.css | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index f24ffdc9a..c485ea7e2 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,11 +1,16 @@ let inputTime = 0; let timer = null; +let changeBgColor = false; function setAlarm() { inputTime = Number(document.querySelector("#alarmSet").value); if (Number.isInteger(inputTime) && !isNaN(inputTime) && inputTime >= 0) { if (inputTime === 10) { + changeBgColor = true; + } else if (inputTime === 0) { + displayTime(inputTime); + playAlarm(); } displayTime(inputTime); if (timer) clearInterval(timer); @@ -30,10 +35,21 @@ function countDown() { if (inputTime === 0) { playAlarm(); + + if (changeBgColor) { + changeColor(); + changeBgColor = false; + } + clearInterval(timer); timer = null; } } + +function changeColor() { + const bgColor = document.querySelector("div"); + bgColor.classList.add("myBgColor"); +} /* the the value for time remaining check its a valid time (greater than 00:00) diff --git a/Sprint-3/alarmclock/style.css b/Sprint-3/alarmclock/style.css index 0c72de38b..044719f8d 100644 --- a/Sprint-3/alarmclock/style.css +++ b/Sprint-3/alarmclock/style.css @@ -6,6 +6,10 @@ transform: translate(-50%, -50%); } +.myBgColor { + background-color: #f0f8ff; +} + #alarmSet { margin: 20px; } From 250453e0f772e66ac2a5f00334d14b9912066b05 Mon Sep 17 00:00:00 2001 From: asaniDev Date: Mon, 8 Dec 2025 10:56:12 +0000 Subject: [PATCH 08/14] Revert "added all tests to test, started mean.js but not finished" This reverts commit 5007c4b2e7454bed90a8cb18e7332329a4f67932. --- prep/mean.js | 18 ------------------ prep/mean.test.js | 22 ---------------------- prep/package.json | 16 ---------------- 3 files changed, 56 deletions(-) delete mode 100644 prep/mean.js delete mode 100644 prep/mean.test.js delete mode 100644 prep/package.json diff --git a/prep/mean.js b/prep/mean.js deleted file mode 100644 index 31f463f9c..000000000 --- a/prep/mean.js +++ /dev/null @@ -1,18 +0,0 @@ -//a data structure is used to group data together. it is a collection of data which has functions which allow you to access and manipulate the data. -//an array is a zero indexed collection of data that holds data in an ordered list. -function calculateMean(list) { - let total = 0; - - for (const item of list) { - total += item; - } -} - -function calculateMedian(list) { - const middleIndex = Math.floor(list.length / 2); - const median = list.splice(middleIndex, 1)[0]; - - return median; -} - -calculateMean([10, 20, 30, 40, 50]); diff --git a/prep/mean.test.js b/prep/mean.test.js deleted file mode 100644 index 386732522..000000000 --- a/prep/mean.test.js +++ /dev/null @@ -1,22 +0,0 @@ -test("calculates the mean of a list of numbers", () => { - const list = [3, 50, 7]; - const currentOutput = calculateMean(list); - const targetOutput = 20; - - expect(currentOutput).toEqual(targetOutput); -}); - -test("calculates the median of a list of odd length", () => { - const list = [10, 20, 30, 50, 60]; - const currentOutput = calculateMedian(list); - const targetOutput = 30; - - expect(currentOutput).toEqual(targetOutput); -}); - -test("doesn't modify the input", () => { - const list = [1, 2, 3]; - calculateMedian(list); - - expect(list).toEqual([1, 2, 3]); // Note that the toEqual matcher checks the values inside arrays when comparing them - it doesn't use `===` on the arrays, we know that would always evaluate to false. -}); diff --git a/prep/package.json b/prep/package.json deleted file mode 100644 index 2301e1638..000000000 --- a/prep/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "prep", - "version": "1.0.0", - "description": "", - "main": "mean.js", - "scripts": { - "test": "jest" - }, - "keywords": [], - "author": "", - "license": "ISC", - "type": "commonjs", - "devDependencies": { - "jest": "^30.2.0" - } -} From 9819f2c63e51f6077ae0765db0560e958def53a3 Mon Sep 17 00:00:00 2001 From: asaniDev Date: Mon, 8 Dec 2025 10:56:12 +0000 Subject: [PATCH 09/14] Revert "predicted the result of each file before fixing them" This reverts commit f21c96e6e26ba3ce80b0bf42afe82a6ec0937e1b. --- Sprint-2/debug/address.js | 4 +--- Sprint-2/debug/author.js | 4 +--- Sprint-2/debug/recipe.js | 10 +++------- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Sprint-2/debug/address.js b/Sprint-2/debug/address.js index 41ce8e624..940a6af83 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -1,10 +1,8 @@ // Predict and explain first... -//the original code is using the wrong notation to access our object this will return undefined as we do not have a 0 property. // This code should log out the houseNumber from the address object // but it isn't working... // Fix anything that isn't working -//fixed it by puting "houseNumber" in the square brackets. const address = { houseNumber: 42, @@ -14,4 +12,4 @@ const address = { postcode: "XYZ 123", }; -console.log(`My house number is ${address["houseNumber"]}`); +console.log(`My house number is ${address[0]}`); diff --git a/Sprint-2/debug/author.js b/Sprint-2/debug/author.js index a78491d62..8c2125977 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -1,9 +1,7 @@ // Predict and explain first... -//the method for of is an array method and it would be looking for an indexed list of items rather than a key value pair so an error will be thrown since we are using an object. // This program attempts to log out all the property values in the object. // But it isn't working. Explain why first and then fix the problem -//i can fix this by changing for ... of to for ... in. const author = { firstName: "Zadie", @@ -13,6 +11,6 @@ const author = { alive: true, }; -for (const value in author) { +for (const value of author) { console.log(value); } diff --git a/Sprint-2/debug/recipe.js b/Sprint-2/debug/recipe.js index 47cbc6ba1..6cbdd22cd 100644 --- a/Sprint-2/debug/recipe.js +++ b/Sprint-2/debug/recipe.js @@ -1,10 +1,8 @@ // Predict and explain first... -//it will display the title and number of people it serves on one line then the whole recipe on the next line // This program should log out the title, how many it serves and the ingredients. // Each ingredient should be logged on a new line // How can you fix it? -//by using the string literal to ensure multiple lines, then having the title on the first line, the number served on the next line and ingredients on the third line. using the dot notation to access the properties needed. const recipe = { title: "bruschetta", @@ -12,8 +10,6 @@ const recipe = { ingredients: ["olive oil", "tomatoes", "salt", "pepper"], }; -console.log(`${recipe.title} serves ${recipe.serves} - ingredients: ${recipe.ingredients[0]} - ${recipe.ingredients[1]} - ${recipe.ingredients[2]} - ${recipe.ingredients[3]}`); +console.log(`${recipe.title} serves ${recipe.serves} + ingredients: +${recipe}`); From 6c486d49cda97c6f1071694bded1c1b4541ca960 Mon Sep 17 00:00:00 2001 From: asaniDev Date: Mon, 8 Dec 2025 10:56:12 +0000 Subject: [PATCH 10/14] Revert "installed dependencies" This reverts commit b058970b50ab73fadd1a5b531babf5dc84ec83ff. --- Sprint-2/package-lock.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/Sprint-2/package-lock.json b/Sprint-2/package-lock.json index ceda7296e..9b4c725d6 100644 --- a/Sprint-2/package-lock.json +++ b/Sprint-2/package-lock.json @@ -56,7 +56,6 @@ "integrity": "sha512-Oixnb+DzmRT30qu9d3tJSQkxuygWm32DFykT4bRoORPa9hZ/L4KhVB/XiRm6KG+roIEM7DBQlmg27kw2HZkdZg==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@ampproject/remapping": "^2.2.0", "@babel/code-frame": "^7.25.7", @@ -1369,7 +1368,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "caniuse-lite": "^1.0.30001663", "electron-to-chromium": "^1.5.28", From 3e235c6cec1c52f5e62b0fec4213e002aba85f77 Mon Sep 17 00:00:00 2001 From: asaniDev Date: Mon, 8 Dec 2025 10:56:12 +0000 Subject: [PATCH 11/14] Revert "made up tests and then created functions to pass the required tests in implement folder" This reverts commit b63c6de42d9bc9b7336434491be58650ab6d815f. --- Sprint-2/implement/contains.js | 33 +--------------------- Sprint-2/implement/contains.test.js | 11 +------- Sprint-2/implement/lookup.js | 17 +----------- Sprint-2/implement/lookup.test.js | 21 +------------- Sprint-2/implement/querystring.js | 36 +++--------------------- Sprint-2/implement/querystring.test.js | 24 ++-------------- Sprint-2/implement/tally.js | 38 +------------------------- Sprint-2/implement/tally.test.js | 17 +----------- 8 files changed, 12 insertions(+), 185 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index 12b9231c3..cd779308a 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,34 +1,3 @@ -function contains(checkObj, checkProp) { - if ( - typeof checkObj === "object" && - checkObj !== null && - !Array.isArray(checkObj) - ) { - const checkKeys = Object.keys(checkObj); - let isProperty = false; - - if (checkKeys.length === 0) { - return false; - } - - if (Object.hasOwn(checkObj, checkProp)) { - return true; - } else { - for (let key of checkKeys) { - if (key === checkProp) { - isProperty = true; - } - } - - if (isProperty === false) { - return false; - } - } - } else { - throw new Error("error invalid parameter please provide an object"); - } -} - -contains({ d: "me" }, 4); +function contains() {} module.exports = contains; diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 80a49f8cd..326bdb1f2 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -20,25 +20,16 @@ as the object doesn't contains a key of 'c' // Given an empty object // When passed to contains // Then it should return false -test("contains on empty object returns false", () => - expect(contains({}, "a")).toBe(false)); +test.todo("contains on empty object returns false"); // Given an object with properties // When passed to contains with an existing property name // Then it should return true -test("returns true when an object contains a property that matches the one passed to contains", () => - expect(contains({ area: "Manchester" }, "area")).toBe(true)); // Given an object with properties // When passed to contains with a non-existent property name // Then it should return false -test("returns false when an object with properties is passed to contains with a non-existent property name", () => - expect(contains({ area: "Manchester" }, "town")).toBe(false)); // Given invalid parameters like an array // When passed to contains // Then it should return false or throw an error -test("should throw an error when when an invalid parameter like an array is passed to contains", () => - expect(() => contains([1, 4], 4)).toThrow( - "error invalid parameter please provide an object" - )); diff --git a/Sprint-2/implement/lookup.js b/Sprint-2/implement/lookup.js index dacb9fc31..a6746e07f 100644 --- a/Sprint-2/implement/lookup.js +++ b/Sprint-2/implement/lookup.js @@ -1,20 +1,5 @@ -function createLookup(inputArray) { +function createLookup() { // implementation here - const returnObject = {}; - - if (Array.isArray(inputArray)) { - if (inputArray.length === 0) { - return "passed array was empty, no values to display"; - } - - for (let item of inputArray) { - returnObject[item[0]] = item[1]; - } - - return returnObject; - } else { - throw new Error("error incorrect parameter passed please provide an array"); - } } module.exports = createLookup; diff --git a/Sprint-2/implement/lookup.test.js b/Sprint-2/implement/lookup.test.js index 7c5fd6a40..547e06c5a 100644 --- a/Sprint-2/implement/lookup.test.js +++ b/Sprint-2/implement/lookup.test.js @@ -1,25 +1,6 @@ const createLookup = require("./lookup.js"); -test("creates a country currency code lookup for multiple codes", () => { - expect( - createLookup([ - ["US", "USD"], - ["CA", "CAD"], - ["MW", "MWK"], - ["ZW", "ZWD"], - ]) - ).toEqual({ US: "USD", CA: "CAD", MW: "MWK", ZW: "ZWD" }); -}); - -test("if passed an empty array , should print a message telling user array is empty", () => { - expect(createLookup([])).toBe("passed array was empty, no values to display"); -}); - -test("if passed parameter which is not an array throw an error", () => { - expect(() => createLookup("US, USD")).toThrow( - "error incorrect parameter passed please provide an array" - ); -}); +test.todo("creates a country currency code lookup for multiple codes"); /* diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index 8bd59028e..45ec4e5f3 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -3,42 +3,14 @@ function parseQueryString(queryString) { if (queryString.length === 0) { return queryParams; } + const keyValuePairs = queryString.split("&"); - if (queryString.includes("&")) { - const keyValuePairs = queryString.split("&"); - - for (const pair of keyValuePairs) { - let countMatch = 0; - - if (pair.includes("=")) { - const equalSignIndex = pair.indexOf("="); - - queryParams[pair.slice(0, equalSignIndex)] = pair.slice( - equalSignIndex + 1 - ); - } else { - throw new Error( - "error invalid format string, no = to separate key value pairs" - ); - } - } - } - - if (queryString.includes("=")) { - const equalSignIndex = queryString.indexOf("="); - - queryParams[queryString.slice(0, equalSignIndex)] = queryString.slice( - equalSignIndex + 1 - ); - } else { - throw new Error( - "error invalid format string, no = to separate key value pairs" - ); + for (const pair of keyValuePairs) { + const [key, value] = pair.split("="); + queryParams[key] = value; } return queryParams; } -console.log(`with ${parseQueryString("equation=x=y+1")}`); - module.exports = parseQueryString; diff --git a/Sprint-2/implement/querystring.test.js b/Sprint-2/implement/querystring.test.js index 7bdf55cd3..3e218b789 100644 --- a/Sprint-2/implement/querystring.test.js +++ b/Sprint-2/implement/querystring.test.js @@ -3,30 +3,10 @@ // Below is one test case for an edge case the implementation doesn't handle well. // Fix the implementation for this test, and try to think of as many other edge cases as possible - write tests and fix those too. -const parseQueryString = require("./querystring.js"); - -test("parseQueryString receives an empty string", () => { - expect(parseQueryString("")).toEqual({}); -}); +const parseQueryString = require("./querystring.js") test("parses querystring values containing =", () => { expect(parseQueryString("equation=x=y+1")).toEqual({ - equation: "x=y+1", + "equation": "x=y+1", }); }); - -test("if our function is passed only one key - value pair", () => { - expect(parseQueryString("color=brown")).toEqual({ color: "brown" }); -}); - -test("parses querystring without an =, it should throw an error", () => { - expect(() => parseQueryString("colorisequaltobrown")).toThrow( - "error invalid format string, no = to separate key value pairs" - ); -}); - -test("if our function is passed only one string but there is no =", () => { - expect(parseQueryString("color,brown")).toEqual( - "error invalid format string, no = to separate key value pair" - ); -}); diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index cbdd2aecc..f47321812 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -1,39 +1,3 @@ -function tally(inputArray) { - if (Array.isArray(inputArray)) { - if (inputArray.length === 0) { - return {}; - } - - let itemCount = 0; - const tallyObject = {}; - let n = 0; - - while (inputArray.length > 0) { - const tempArray = []; - let i = 0; - let currentArrayItem = inputArray[0]; - - while (i < inputArray.length) { - if (currentArrayItem === inputArray[i]) { - itemCount++; - tempArray.push(inputArray.splice(i, 1)); - i--; - } - - i++; - } - - if (tempArray.length > 0) { - tallyObject[tempArray[0]] = tempArray.length; - } - } - console.log(`the new array and the new object ${tallyObject}`); - return tallyObject; - } else { - throw new Error("error invalid input passed, please provide an array"); - } -} - -console.log(`new object is ${tally(["a", "a", "b", "c", "c", "d", "a"])}`); +function tally() {} module.exports = tally; diff --git a/Sprint-2/implement/tally.test.js b/Sprint-2/implement/tally.test.js index afc6315aa..2ceffa8dd 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -23,27 +23,12 @@ const tally = require("./tally.js"); // Given an empty array // When passed to tally // Then it should return an empty object -test("tally on an empty array returns an empty object", () => { - expect(tally([])).toEqual({}); -}); +test.todo("tally on an empty array returns an empty object"); // Given an array with duplicate items // When passed to tally // Then it should return counts for each unique item -test("given an array with duplicate items it should return counts for each unique item ", () => { - expect(tally(["a", "a", "b", "c", "c", "d", "a"])).toEqual({ - a: 3, - b: 1, - c: 2, - d: 1, - }); -}); // Given an invalid input like a string // When passed to tally // Then it should throw an error -test("should throw an error when tally is passed an invalid input like a string", () => { - expect(() => tally("b,b,c,d,e,e,f")).toThrow( - "error invalid input passed, please provide an array" - ); -}); From 972539973fdfbc2d63b5e59de6952e8571379afe Mon Sep 17 00:00:00 2001 From: asaniDev Date: Mon, 8 Dec 2025 10:56:12 +0000 Subject: [PATCH 12/14] Revert "fixed invert function,answered questions and added tests to check it works as expected" This reverts commit e17bf3024c0beb907faf24b371e3997fec46f2aa. --- Sprint-2/interpret/invert.js | 37 ++----------------------------- Sprint-2/interpret/invert.test.js | 31 -------------------------- 2 files changed, 2 insertions(+), 66 deletions(-) delete mode 100644 Sprint-2/interpret/invert.test.js diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index 0c3bab967..bb353fb1f 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -9,54 +9,21 @@ function invert(obj) { const invertedObj = {}; - if (Object.prototype.toString.call(obj) === "[object Object]") { - for (const [key, value] of Object.entries(obj)) { - invertedObj[value] = key; - } - } else { - throw new Error("error invalid input entered, expecting an object"); + for (const [key, value] of Object.entries(obj)) { + invertedObj.key = value; } return invertedObj; } -module.exports = invert; - -console.log( - `the return value when invert is called with ${invert({ - cars: { toyota: 2, bmw: 1, benz: 4 }, - })}` -); - -/* -for (const property in obj) { - if (typeof obj[property] !== "string") { - throw new Error( - "error invalid input entered, expecting an object to have only strings as values" - ); - } else { - - } - } - -*/ - // a) What is the current return value when invert is called with { a : 1 } -//it returns a string describing the object. // b) What is the current return value when invert is called with { a: 1, b: 2 } -//it aso returns a string describing the object. // c) What is the target return value when invert is called with {a : 1, b: 2} -//the target return value is {"1": "a", "2": "b"}. // c) What does Object.entries return? Why is it needed in this program? -//it returns an array made up of arrays of the original objects key - value pairs. -//it allows us to unpack the contents of the object into an array which can then be used to create the new object // d) Explain why the current return value is different from the target output -//because we used dot notation to assign a value to our key, this creates a property called key -//and assigns it a value. we want our key to get its name from a variable so we need to use bracket notation. // e) Fix the implementation of invert (and write tests to prove it's fixed!) -//we can fix it by using invertedObj[value] = key. diff --git a/Sprint-2/interpret/invert.test.js b/Sprint-2/interpret/invert.test.js deleted file mode 100644 index 7ce178b17..000000000 --- a/Sprint-2/interpret/invert.test.js +++ /dev/null @@ -1,31 +0,0 @@ -const invert = require("./invert.js"); - -describe("tests to see if invert function swaps around the keys and values in a given object", () => { - test("if invert is passed a value which is not an object, it should throw an error", () => { - expect(() => - invert([ - ["x", 10], - ["y", 20], - ]) - ).toThrow("error invalid input entered, expecting an object"); - }); - - test("if we are passed an empty object we should return an empty object", () => { - expect(invert({})).toEqual({}); - }); - - test("given an object with key value pairs, it should swap the keys and values in the object", () => { - expect(invert({ x: 10, y: 20 })).toEqual({ 10: "x", 20: "y" }); - expect( - invert({ city: "Birmingham", population: "345908", boroughs: "20" }) - ).toEqual({ Birmingham: "city", 345908: "population", 20: "boroughs" }); - }); -}); - -/* -test("if invert is passed an object which has an array or object as one of its values, it should throw an error", () => { - expect(() => invert({ cars: { toyota: 2, bmw: 1, benz: 4 } })).toThrow( - "error invalid input entered, expecting an object to have only strings as values" - ); - }); -*/ From da00a5e452afab32413c1918bd939b9040490030 Mon Sep 17 00:00:00 2001 From: asaniDev Date: Tue, 16 Dec 2025 02:44:51 +0000 Subject: [PATCH 13/14] removed unnecesary functions and reset timer --- Sprint-3/alarmclock/alarmclock.js | 8 ++++++-- Sprint-3/alarmclock/index.html | 4 +++- Sprint-3/alarmclock/style.css | 24 ++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index c485ea7e2..9d8c2507a 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -5,15 +5,19 @@ let changeBgColor = false; function setAlarm() { inputTime = Number(document.querySelector("#alarmSet").value); - if (Number.isInteger(inputTime) && !isNaN(inputTime) && inputTime >= 0) { + if (Number.isInteger(inputTime) && inputTime >= 0) { if (inputTime === 10) { changeBgColor = true; } else if (inputTime === 0) { displayTime(inputTime); playAlarm(); + document.querySelector("#alarmSet").value = ""; } displayTime(inputTime); - if (timer) clearInterval(timer); + if (timer) { + clearInterval(timer); + timer = null; + } timer = setInterval(countDown, 1000); } } diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 4a91379d3..d0929d540 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -8,7 +8,9 @@
-

Time Remaining: 00:00

+
+ Time Remaining: 00:00 +
diff --git a/Sprint-3/alarmclock/style.css b/Sprint-3/alarmclock/style.css index 044719f8d..946c279f2 100644 --- a/Sprint-3/alarmclock/style.css +++ b/Sprint-3/alarmclock/style.css @@ -10,10 +10,30 @@ background-color: #f0f8ff; } -#alarmSet { +#theTime { + font-size: 24px; + text-align: center; margin: 20px; } -h1 { +#timeRemaining { + font-size: 24px; text-align: center; + margin: 20px; +} + +#alarmSet { + margin: 20px; + font-size: 18px; + text-align: center; +} +#set { + font-size: 14px; + padding: 5px; +} + +#stop { + font-size: 14px; + padding: 5px; + margin-left: 20px; } From 24540869f0ca71af8a7d9269eb77d882eded999e Mon Sep 17 00:00:00 2001 From: asaniDev Date: Tue, 16 Dec 2025 22:26:31 +0000 Subject: [PATCH 14/14] removed redundant code, added code to stop alarm if runnng --- Sprint-3/alarmclock/alarmclock.js | 67 +++++++++++-------------------- 1 file changed, 23 insertions(+), 44 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 9d8c2507a..9b823f9f0 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -5,30 +5,37 @@ let changeBgColor = false; function setAlarm() { inputTime = Number(document.querySelector("#alarmSet").value); - if (Number.isInteger(inputTime) && inputTime >= 0) { - if (inputTime === 10) { - changeBgColor = true; - } else if (inputTime === 0) { - displayTime(inputTime); - playAlarm(); - document.querySelector("#alarmSet").value = ""; - } + if (!Number.isInteger(inputTime) || inputTime < 0) { + return; + } + if (inputTime === 10) { + changeBgColor = true; + } else if (inputTime === 0) { displayTime(inputTime); - if (timer) { - clearInterval(timer); - timer = null; - } - timer = setInterval(countDown, 1000); + playAlarm(); + document.querySelector("#alarmSet").reset(); } + displayTime(inputTime); + if (typeof audio !== "undefined" && audio) { + audio.pause(); + try { + audio.currentTime = 0; + } catch (e) {} + audio.loop = false; // disable looping if it was set + } + if (timer) { + clearInterval(timer); + } + timer = setInterval(countDown, 1000); } function displayTime(totalTime) { const seconds = totalTime % 60; const minutes = (totalTime - seconds) / 60; - const timeLeft = document.querySelector("#timeRemaining"); - timeLeft.innerText = `Time Remaining: ${minutes + const timeLeft = document.querySelector("#theTime"); + timeLeft.innerText = `${minutes.toString().padStart(2, 0)}:${seconds .toString() - .padStart(2, 0)}:${seconds.toString().padStart(2, 0)}`; + .padStart(2, 0)}`; } function countDown() { @@ -83,31 +90,3 @@ function pauseAlarm() { } window.onload = setup; - -/* -Given the user has entered a number in the input field When the user clicks the “Set Alarm” button Then the “Time Remaining” title should update to show the entered number in mm:ss format - take value from in input field and store it in a variable inputTime - check inputTime value is within the accepted range? - take variable inputTime and display it in time remaining section - - -Given the alarm is set with a valid time When one second passes Then the “Time Remaining” title should decrement by 1 second - the the value for time remaining - check its a valid time (greater than 00:00) - decrease value of time remaining by 1 sec for each sec that passes - -Given the alarm is set with a time of 00:00 When the timer reaches 00:00 Then the alarm sound should play continuously - check time remaining, if it is equal to 00:00 then sound alarm - - -Given the alarm sound is currently playing When the user clicks the “Stop Alarm” button Then the alarm sound should stop playing - check if stop alarm button has been pressed - if true then check if alarm sound is playing then stop alarm sound if true - -Given the alarm is set with a time of 00:10 When the timer reaches 00:00 Then the background color should change And the alarm sound should play - if inputTime is 00:10 and timer reaches 0 the change background color - play alarm sound - -Given the user has not set an alarm When the page first loads Then the “Time Remaining” title should show 00:00 And no alarm sound should play -when page loads time remaining should 0 and no alarm sound should play -*/