From a232d1334fe81e2a7134b48a50d3e7fc24ff11db Mon Sep 17 00:00:00 2001 From: ldfajardo10-tech Date: Tue, 25 Nov 2025 13:37:06 +0100 Subject: [PATCH 01/17] 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/17] "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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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 3c8a26f0fd2927439fceb3c6d393a755bb701079 Mon Sep 17 00:00:00 2001 From: ldfajardo10-tech Date: Wed, 7 Jan 2026 18:42:57 +0100 Subject: [PATCH 14/17] exercise invert test corrections --- Sprint-2/interpret/invert.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index a9bd4ae06..dd6afadeb 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -30,14 +30,14 @@ function invert(obj) { // 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 }); + expect(invert({ "a": 1, "b": 2 })).toEqual({ 1: "a", 2: "b" }); }); test("inverts object with strings value", () => { - expect(invert({ a: "hello", b: "world" })).toBe({ "hello": a, "world": b }); + expect(invert({ "a": "hello", "b": "world" })).toEqual({ "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 }); + expect(invert({ "a": "hello", "b": 5 })).toEqual({ hello: "a", 5 : "b" }); }); From 78136fe3b6e71e5c1767d007caa62051b7a08936 Mon Sep 17 00:00:00 2001 From: ldfajardo10-tech Date: Wed, 7 Jan 2026 19:35:49 +0100 Subject: [PATCH 15/17] jest tests contains exercises --- Sprint-2/implement/contains.test.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 326bdb1f2..a3170e07b 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -20,16 +20,28 @@ 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("contains return true for existing property", () => { + const obj = {a:5, b:10}; + expect(contains(obj, "a")).toBe(true); +}); // Given an object with properties // When passed to contains with a non-existent property name // Then it should return false - +test("contains return false for a non-existent property", () => { + const obj = { a: 5, b: 10 }; + expect(contains(obj, "d")).toBe(false); +}); // Given invalid parameters like an array // When passed to contains // Then it should return false or throw an error +test("contains return throw an error message for invalid parameters like an array", () => { + const arr = ["a", "b", "c", "d"]; + expect(() => contains(arr, "d")).toThrow("invalid input"); +}); \ No newline at end of file From b5cd60d89aa7dae1e9c7d4ea074f488286cdbf4f Mon Sep 17 00:00:00 2001 From: ldfajardo10-tech Date: Wed, 7 Jan 2026 19:46:38 +0100 Subject: [PATCH 16/17] lookup jest tests exercise solution --- Sprint-2/implement/lookup.js | 9 +-------- Sprint-2/implement/lookup.test.js | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Sprint-2/implement/lookup.js b/Sprint-2/implement/lookup.js index 5573ac36c..6a4466d7b 100644 --- a/Sprint-2/implement/lookup.js +++ b/Sprint-2/implement/lookup.js @@ -8,12 +8,5 @@ function createLookup(codePairs) { } - const countryCurrency = [ - ["US", "USD"], - ["CA", "CAD"], - ]; - -const result = createLookup(countryCurrency); -console.log(result); - + module.exports = createLookup; diff --git a/Sprint-2/implement/lookup.test.js b/Sprint-2/implement/lookup.test.js index 547e06c5a..78035befa 100644 --- a/Sprint-2/implement/lookup.test.js +++ b/Sprint-2/implement/lookup.test.js @@ -33,3 +33,29 @@ It should return: 'CA': 'CAD' } */ + +test("returns empty object when passed an empty array", () => { + expect(createLookup([])).toEqual({}); +}); + +test("returns null when passed a non-array input", () => { + expect(createLookup("hello")).toBeNull(); + expect(createLookup({})).toBeNull(); + expect(createLookup(123)).toBeNull(); +}); + +test("creates a lookup object from an array of code pairs", () => { + const countryCurrency = [ + ["US", "USD"], + ["CA", "CAD"], + ["MX", "MXN"], + ]; + + const expected = { + US: "USD", + CA: "CAD", + MX: "MXN", + }; + + expect(createLookup(countryCurrency)).toEqual(expected); +}); \ No newline at end of file From 48586efa821fc5c18c72ac7f844cfafc32192eec Mon Sep 17 00:00:00 2001 From: ldfajardo10-tech Date: Wed, 7 Jan 2026 20:08:44 +0100 Subject: [PATCH 17/17] jest tests tally exercise solutions --- Sprint-2/implement/lookup.test.js | 2 -- Sprint-2/implement/tally.js | 5 ----- Sprint-2/implement/tally.test.js | 19 ++++++++++++++++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Sprint-2/implement/lookup.test.js b/Sprint-2/implement/lookup.test.js index 78035befa..eae40a747 100644 --- a/Sprint-2/implement/lookup.test.js +++ b/Sprint-2/implement/lookup.test.js @@ -1,7 +1,5 @@ const createLookup = require("./lookup.js"); -test.todo("creates a country currency code lookup for multiple codes"); - /* Create a lookup object of key value pairs from an array of code pairs diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index 7142e2afa..a9e53d26a 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -18,10 +18,5 @@ function tally(arr) { } -console.log(tally(["a","a","c"])); -console.log(tally(["a", "5", "5"])); -console.log(tally([])); -console.log(tally("hello world")); - module.exports = tally; diff --git a/Sprint-2/implement/tally.test.js b/Sprint-2/implement/tally.test.js index 2ceffa8dd..019ffdf97 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -19,16 +19,29 @@ const tally = require("./tally.js"); // Given a function called tally // When passed an array of items // Then it should return an object containing the count for each unique item - +test("return an object containing the count for each unique item", () => { + const arr = ["a", "a", "b", "c"]; + const expected = { a: 2, b: 1, c: 1 }; + expect(tally(arr)).toEqual(expected); +}); // 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("should return an empty object for an empty array input", () => { + expect(tally([])).toEqual({}); +}); // Given an array with duplicate items // When passed to tally // Then it should return counts for each unique item - +test("should return an object with the counts of each unique item for an input with duplicates", () => { + const dup = ["a", "a", "c"]; + const expected = {a:2, c:1}; + expect(tally(dup)).toEqual(expected); +}); // Given an invalid input like a string // When passed to tally // Then it should throw an error +test("throw an error given a valid input like a string", () => { + expect(() => tally("hello")).toThrow("Input must be an array"); +}); \ No newline at end of file