From a232d1334fe81e2a7134b48a50d3e7fc24ff11db Mon Sep 17 00:00:00 2001 From: ldfajardo10-tech Date: Tue, 25 Nov 2025 13:37:06 +0100 Subject: [PATCH 01/14] prep exercise --- Sprint-3/prep/exerciseprep.html | 24 ++++++++++++++++++++++++ Sprint-3/prep/script.js | 13 +++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 Sprint-3/prep/exerciseprep.html create mode 100644 Sprint-3/prep/script.js diff --git a/Sprint-3/prep/exerciseprep.html b/Sprint-3/prep/exerciseprep.html new file mode 100644 index 000000000..a3bef2628 --- /dev/null +++ b/Sprint-3/prep/exerciseprep.html @@ -0,0 +1,24 @@ + + + + + + Document + + +
+

Character limit

+ + +

You have 200 characters remaining

+
+ + + \ No newline at end of file diff --git a/Sprint-3/prep/script.js b/Sprint-3/prep/script.js new file mode 100644 index 000000000..91efa7c64 --- /dev/null +++ b/Sprint-3/prep/script.js @@ -0,0 +1,13 @@ + //select the elements from the html file with query selector calling the id (#) + const textarea = document.querySelector("#comment-input"); + const info = document.querySelector("#character-limit-info"); +//get the limit of characters + const maxLength = Number(textarea.getAttribute("maxlength")); +// add the event listener with the "input" for typing in a text field. + textarea.addEventListener("input", () => { + const typed = textarea.value.length; + const remaining = maxLength - typed; + //create the string and print the result of the remaining characters + info.textContent = `You have ${remaining} characters remaining`; + }); + From 075e2039d8f0dbba193ca97810cc38e6d6a1405e Mon Sep 17 00:00:00 2001 From: ldfajardo10-tech Date: Fri, 28 Nov 2025 21:27:31 +0100 Subject: [PATCH 02/14] "readme update" --- Sprint-3/slideshow/readme.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sprint-3/slideshow/readme.md b/Sprint-3/slideshow/readme.md index a0c06e4ff..c4645f630 100644 --- a/Sprint-3/slideshow/readme.md +++ b/Sprint-3/slideshow/readme.md @@ -6,8 +6,7 @@ First off, once you've branched off `main`, then update the title element in `in Make a website which allows the user to navigate a set of images (first manually, then with an auto-playing slideshow). -[Try this live demo!](https://cyf-image-carousel.netlify.app/) - +[Try this live demo!]heck link in original repository # Level 1 Challenge Make forward and back buttons to move _manually_ in that direction through a list of at least 4 images. From 5ee7490b1d0cb33b4dabaa43ee78bc806cca870f Mon Sep 17 00:00:00 2001 From: ldfajardo10-tech Date: Wed, 3 Dec 2025 18:10:37 +0100 Subject: [PATCH 03/14] exercise address solution --- Sprint-2/debug/address.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/debug/address.js b/Sprint-2/debug/address.js index 940a6af83..cb7dd2a69 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -9,7 +9,7 @@ const address = { street: "Imaginary Road", city: "Manchester", country: "England", - postcode: "XYZ 123", + postcode: "xyz 123", }; -console.log(`My house number is ${address[0]}`); +console.log(`my house number is ${address.houseNumber}`); From 51f93b01057b31130b5bfa773cb8f808ea924b56 Mon Sep 17 00:00:00 2001 From: ldfajardo10-tech Date: Wed, 3 Dec 2025 18:14:37 +0100 Subject: [PATCH 04/14] update exercise address --- Sprint-2/debug/address.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/debug/address.js b/Sprint-2/debug/address.js index cb7dd2a69..a3217b713 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -1,5 +1,6 @@ // Predict and explain first... - +// the const is an object, not an array, so [0] in the console log isn't correc +t // This code should log out the houseNumber from the address object // but it isn't working... // Fix anything that isn't working From 1d223bc078feb7e46e52f137150ed35c91c260cd Mon Sep 17 00:00:00 2001 From: ldfajardo10-tech Date: Wed, 3 Dec 2025 18:43:08 +0100 Subject: [PATCH 05/14] exercise author solution --- Sprint-2/debug/author.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/debug/author.js b/Sprint-2/debug/author.js index 8c2125977..3b3d1a776 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -1,5 +1,5 @@ // Predict and explain first... - +// we should take the object and access to the values through dotation. // 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 @@ -11,6 +11,6 @@ const author = { alive: true, }; -for (const value of author) { +for (const value of Object.values(author)) { console.log(value); } From 50ba1de5317601f1671f557cc61722dd20a14613 Mon Sep 17 00:00:00 2001 From: ldfajardo10-tech Date: Wed, 3 Dec 2025 19:06:43 +0100 Subject: [PATCH 06/14] exercise recipe solution --- Sprint-2/debug/recipe.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-2/debug/recipe.js b/Sprint-2/debug/recipe.js index 6cbdd22cd..6822a4e1f 100644 --- a/Sprint-2/debug/recipe.js +++ b/Sprint-2/debug/recipe.js @@ -10,6 +10,6 @@ const recipe = { ingredients: ["olive oil", "tomatoes", "salt", "pepper"], }; -console.log(`${recipe.title} serves ${recipe.serves} - ingredients: -${recipe}`); +console.log(`${recipe.title}`); +console.log(`serves: ${recipe.serves}`); +recipe.ingredients.forEach(i => console.log("-"+i)); \ No newline at end of file From be54ebf8468fc6e6ff11f9b9cef518c6ca83070b Mon Sep 17 00:00:00 2001 From: ldfajardo10-tech Date: Wed, 3 Dec 2025 19:59:45 +0100 Subject: [PATCH 07/14] exercise constains solution --- Sprint-2/implement/contains.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index cd779308a..501bbb02a 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,3 +1,23 @@ -function contains() {} +function contains(obj, prop) { + + if (typeof obj !== "object" && obj !== null ) { + return false; + } else if (Array.isArray(obj)) { + throw new Error ("invalid input"); + } + + return prop in obj; + +} +console.log(contains({ a: 1, b: 2 }, "a")); +console.log(contains({ a: 1, b: 2 }, "c")); +console.log(contains({})); +console.log(contains({undefined},"b")); + +try { + console.log(contains([1, 2, 3], "3")); +} catch (E) { + console.log(E.message); +} module.exports = contains; From 5e4b7002bc219dec8b41a997f6459182d7a914a4 Mon Sep 17 00:00:00 2001 From: ldfajardo10-tech Date: Wed, 3 Dec 2025 20:02:15 +0100 Subject: [PATCH 08/14] fix mistake wrong operator line 3 --- Sprint-2/implement/contains.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index 501bbb02a..d2fed0617 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,6 +1,6 @@ function contains(obj, prop) { - if (typeof obj !== "object" && obj !== null ) { + if (typeof obj !== "object" && obj === null ) { return false; } else if (Array.isArray(obj)) { throw new Error ("invalid input"); From 2a84cab268bc2b7a6544486b4488114f58352d33 Mon Sep 17 00:00:00 2001 From: ldfajardo10-tech Date: Wed, 3 Dec 2025 20:06:05 +0100 Subject: [PATCH 09/14] comments update exercise contains --- Sprint-2/implement/contains.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index d2fed0617..9d23d92cf 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,12 +1,12 @@ function contains(obj, prop) { - if (typeof obj !== "object" && obj === null ) { + if (typeof obj !== "object" && obj === null ) { //typeof to check if the key is an object return false; - } else if (Array.isArray(obj)) { + } else if (Array.isArray(obj)) { //array.isarray to check that the obj is an array, so we throw an error message throw new Error ("invalid input"); } - return prop in obj; + return prop in obj; //in method to check if a property is in the object } console.log(contains({ a: 1, b: 2 }, "a")); @@ -15,7 +15,7 @@ console.log(contains({})); console.log(contains({undefined},"b")); try { - console.log(contains([1, 2, 3], "3")); + console.log(contains([1, 2, 3], "3")); } catch (E) { console.log(E.message); } From 397fba6c9d916da68cea90fecdec4e3d080c2f2e Mon Sep 17 00:00:00 2001 From: ldfajardo10-tech Date: Fri, 5 Dec 2025 19:24:03 +0100 Subject: [PATCH 10/14] exercise lookup solution --- Sprint-2/implement/lookup.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Sprint-2/implement/lookup.js b/Sprint-2/implement/lookup.js index a6746e07f..5573ac36c 100644 --- a/Sprint-2/implement/lookup.js +++ b/Sprint-2/implement/lookup.js @@ -1,5 +1,19 @@ -function createLookup() { - // implementation here -} +function createLookup(codePairs) { + + if (!Array.isArray(codePairs)) { + return null; + } + + return Object.fromEntries(codePairs); //convert the code pairs arrays into object + +} + + const countryCurrency = [ + ["US", "USD"], + ["CA", "CAD"], + ]; + +const result = createLookup(countryCurrency); +console.log(result); module.exports = createLookup; From 6b982ad2358226f894703cd8a5f931be56de2728 Mon Sep 17 00:00:00 2001 From: ldfajardo10-tech Date: Sun, 7 Dec 2025 12:44:20 +0100 Subject: [PATCH 11/14] tally exercise solution --- Sprint-2/implement/tally.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index f47321812..7142e2afa 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -1,3 +1,27 @@ -function tally() {} +function tally(arr) { + + if (!Array.isArray(arr)) { + throw new TypeError("Input must be an array"); + } + + const counts = {}; //store the result as an object + + for (const items of arr) { //for... of loop to count the items + if (counts[items]) { + counts[items] += 1; + } else { + counts[items] = 1; + } + } + + return counts; + +} + +console.log(tally(["a","a","c"])); +console.log(tally(["a", "5", "5"])); +console.log(tally([])); +console.log(tally("hello world")); + module.exports = tally; From d72f21fcfdd99961d4c1a6b46ae3c699a76889b2 Mon Sep 17 00:00:00 2001 From: ldfajardo10-tech Date: Sun, 7 Dec 2025 14:16:04 +0100 Subject: [PATCH 12/14] exercise querystring implementation and edge cases for test --- Sprint-2/implement/querystring.js | 7 ++++--- Sprint-2/implement/querystring.test.js | 12 ++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index 45ec4e5f3..b1ccb095f 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -6,11 +6,12 @@ function parseQueryString(queryString) { const keyValuePairs = queryString.split("&"); for (const pair of keyValuePairs) { - const [key, value] = pair.split("="); + const [key, ...rest] = pair.split("="); //split the first = from the key + const value = rest.join("="); //join the value queryParams[key] = value; - } + } return queryParams; -} +} module.exports = parseQueryString; diff --git a/Sprint-2/implement/querystring.test.js b/Sprint-2/implement/querystring.test.js index 3e218b789..2f120598f 100644 --- a/Sprint-2/implement/querystring.test.js +++ b/Sprint-2/implement/querystring.test.js @@ -10,3 +10,15 @@ test("parses querystring values containing =", () => { "equation": "x=y+1", }); }); + +test("multiple key-value pairs", () => { + expect(parseQueryString("a=1&b=2")).toEqual({ a: "1", b: "2" }); +}); + +test("only = character", () => { + expect(parseQueryString("=")).toEqual({ "": "" }); +}); + +test("empty key with value", () => { + expect(parseQueryString("=value")).toEqual({ "": "value" }); +}); From 15c78958bca09ec5d5ff9234b0ad0d4f9268949b Mon Sep 17 00:00:00 2001 From: ldfajardo10-tech Date: Sun, 7 Dec 2025 15:36:15 +0100 Subject: [PATCH 13/14] invert exercise solution --- Sprint-2/interpret/invert.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index bb353fb1f..a9bd4ae06 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -10,20 +10,34 @@ function invert(obj) { const invertedObj = {}; for (const [key, value] of Object.entries(obj)) { - invertedObj.key = value; + invertedObj[value] = key; } return invertedObj; } -// a) What is the current return value when invert is called with { a : 1 } +// a) What is the current return value when invert is called with { a : 1 } = { key : 1} -// b) What is the current return value when invert is called with { a: 1, b: 2 } +// b) What is the current return value when invert is called with { a: 1, b: 2 } = { key : 2} -// c) What is the target return value when invert is called with {a : 1, b: 2} +// c) What is the target return value when invert is called with {a : 1, b: 2} = { 1 : a, 2 : b} -// c) What does Object.entries return? Why is it needed in this program? +// c) What does Object.entries return? Why is it needed in this program? = returns an array of key, value pairs. It's important bc we can loop both, key and values. -// d) Explain why the current return value is different from the target output +// d) Explain why the current return value is different from the target output = because invertedObj.key is just setting a property called "key" +// we need to use the [] to access to the variable. + +// e) Fix the implementation of invert (and write tests to prove it's fixed!) + +test("inverts object with numeric strings value", () => { + expect(invert({ a: 1, b: 2 })).toBe({ 1: a, 2: b }); +}); + +test("inverts object with strings value", () => { + expect(invert({ a: "hello", b: "world" })).toBe({ "hello": a, "world": b }); +}); + +test("inverts object with numeric strings value and literal strings value", () => { + expect(invert({ a: "hello", b: 5 })).toBe({ hello: a, 5 : b }); +}); -// e) Fix the implementation of invert (and write tests to prove it's fixed!) From 8f19b253f20b27d24de01eeddf43721f246550cb Mon Sep 17 00:00:00 2001 From: ldfajardo10-tech Date: Mon, 8 Dec 2025 13:26:36 +0100 Subject: [PATCH 14/14] alarmclock implementation --- Sprint-3/alarmclock/alarmclock.js | 47 ++++++++++++++++++++++++++++++- Sprint-3/alarmclock/index.html | 4 +-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..bfb064cfb 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,5 +1,45 @@ -function setAlarm() {} +function setAlarm() { + //get elements from the html file + const input = document.querySelector("#alarmSet"); + const heading = document.querySelector("#timeRemaining"); + const pause = document.querySelector("#pause"); + let totalSeconds = parseInt(input.value, 10); //converting the input into number values (input from html file are always strings) + + if (isNaN(totalSeconds) || totalSeconds <= 0) { //check if is not a number and if the number is 0 or less than 0 to return a message for invalid input + heading.innerText = "Please enter a valid number of seconds"; + return; + } + + //helper function + function formatTime(seconds) { + const minutes = Math.floor(seconds / 60); + const secs = seconds % 60; + return `${minutes.toString().padStart(2, "0")}:${secs + .toString() + .padStart(2, "0")}`; + } + + heading.innerText = `Time Remaining: ${formatTime(totalSeconds)}`; //updating heading + + const timerId = setInterval(() => { //countdown + totalSeconds--; //decrements operator + + heading.innerText = `Time Remaining: ${formatTime(totalSeconds)}`; //updating heading every second after the countdown runs + + if (totalSeconds <= 0) { + clearInterval(timerId); + if (typeof playAlarm === "function") { //only runs if playAlarm is a function (safe code) + playAlarm(); + } + } + }, 1000); + + + + + +} // DO NOT EDIT BELOW HERE var audio = new Audio("alarmsound.mp3"); @@ -12,6 +52,10 @@ function setup() { document.getElementById("stop").addEventListener("click", () => { pauseAlarm(); }); + + document.getElementById("pause").addEventListener("click", () => { + pauseCountDown(); + }); } function playAlarm() { @@ -22,4 +66,5 @@ function pauseAlarm() { audio.pause(); } + window.onload = setup; diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..ecdc8c503 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Alarm Clock App
@@ -13,7 +13,7 @@

Time Remaining: 00:00

- +