From 2baf830ae575af2d229c5205914e65f7bd7916d3 Mon Sep 17 00:00:00 2001 From: Arunkumar Akilan Date: Tue, 17 Mar 2026 09:13:15 +0000 Subject: [PATCH 1/5] feat: clean Sprint-2 implementation and tests --- Sprint-2/debug/address.js | 2 +- Sprint-2/debug/author.js | 13 +++++++---- Sprint-2/debug/recipe.js | 14 +++++++---- Sprint-2/implement/contains.js | 20 +++++++++++++++- Sprint-2/implement/contains.test.js | 32 ++++++++++++++++++++++++++ Sprint-2/implement/lookup.js | 10 ++++++-- Sprint-2/implement/lookup.test.js | 9 ++++++++ Sprint-2/implement/querystring.js | 6 +++-- Sprint-2/implement/querystring.test.js | 15 ++++++++++++ Sprint-2/implement/tally.js | 17 +++++++++++++- Sprint-2/implement/tally.test.js | 9 ++++++++ Sprint-2/interpret/invert.js | 11 +++++++-- Sprint-2/interpret/invert.test.js | 10 ++++++++ 13 files changed, 151 insertions(+), 17 deletions(-) create mode 100644 Sprint-2/interpret/invert.test.js diff --git a/Sprint-2/debug/address.js b/Sprint-2/debug/address.js index 940a6af83..fde180d6d 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -12,4 +12,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..876962002 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -1,5 +1,6 @@ // Predict and explain first... - +// The program throws an error because a for...of loop only works with iterable values like arrays or strings. +// The author variable is an object, which is not iterable by default, so JavaScript cannot loop through it. // 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 @@ -10,7 +11,11 @@ const author = { age: 40, alive: true, }; - -for (const value of author) { - console.log(value); +const values = Object.values(author); +for(const item of values) +{ + console.log(item); } + + + diff --git a/Sprint-2/debug/recipe.js b/Sprint-2/debug/recipe.js index 6cbdd22cd..15a450935 100644 --- a/Sprint-2/debug/recipe.js +++ b/Sprint-2/debug/recipe.js @@ -1,5 +1,6 @@ // Predict and explain first... - +//The title and serves values print correctly because the properties are accessed directly using +// recipe.title and recipe.serves. // 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? @@ -10,6 +11,11 @@ const recipe = { ingredients: ["olive oil", "tomatoes", "salt", "pepper"], }; -console.log(`${recipe.title} serves ${recipe.serves} - ingredients: -${recipe}`); +console.log(`${recipe.title} serves ${recipe.serves}`); +for(const ingredients of recipe.ingredients) +{ + console.log(`*${ingredients}`) +} + +//The program prints the recipe title and number of servings. +// Then it loops through the ingredients array and logs each ingredient on a new line so they are displayed individually instead of printing the whole object. \ No newline at end of file diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index cd779308a..8cee952a2 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,3 +1,21 @@ -function contains() {} +function contains(object, propertyName) { + if(typeof object !== 'object' || Array.isArray(object) || object=== null) + { + throw new Error("It is a invalid object") + } + const newArray = Object.keys(object); + for(let item of newArray) + { + if (item === propertyName) + { + return true + } + + + + } + return false; +} + module.exports = contains; diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 326bdb1f2..b64015f11 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -11,6 +11,38 @@ E.g. contains({a: 1, b: 2}, 'c') // returns false as the object doesn't contains a key of 'c' */ +test("An empty object should return false",()=>{ + const object = {}; + const propertyName = "a"; + expect(contains(object, propertyName)).toEqual(false); +}); + + +test("returns true when the object contains an existing property name", () => { + const object = { a: 1, b: 2, c: 3 }; + const propertyName = "a"; + expect(contains(object, propertyName)).toEqual(true); +}); +test("returns false when the object not contains an existing property name", () => { + const object = { a: 1, b: 2, c: 3 }; + const propertyName = "d"; + expect(contains(object, propertyName)).toEqual(false); +}); +test("Should throw an error for an invalid parameters", () => { + const object = [1,2,3,4,5,6,7]; + const propertyName = "a"; + expect(() => contains(object, propertyName)).toThrow(); +}); +test("Should throw an error for an invalid parameters", () => { + const object = null; + const propertyName = "a"; + expect(() => contains(object, propertyName)).toThrow(); +}); +test("Should throw an error for an invalid parameters", () => { + const object = "hi"; + const propertyName = "a"; + expect(() => contains(object, propertyName)).toThrow(); +}); // Acceptance criteria: // Given a contains function diff --git a/Sprint-2/implement/lookup.js b/Sprint-2/implement/lookup.js index a6746e07f..e5f1addc0 100644 --- a/Sprint-2/implement/lookup.js +++ b/Sprint-2/implement/lookup.js @@ -1,5 +1,11 @@ -function createLookup() { - // implementation here +function createLookup(countryCurrencyPairs) { + const countryCurrencyLookup = {}; + + for (let item of countryCurrencyPairs) { + const [key, value] = [item[0], item[1]]; + countryCurrencyLookup[key] = value; + } + return countryCurrencyLookup; } module.exports = createLookup; diff --git a/Sprint-2/implement/lookup.test.js b/Sprint-2/implement/lookup.test.js index 547e06c5a..a1b82e864 100644 --- a/Sprint-2/implement/lookup.test.js +++ b/Sprint-2/implement/lookup.test.js @@ -2,6 +2,15 @@ const createLookup = require("./lookup.js"); test.todo("creates a country currency code lookup for multiple codes"); +test("An array of arrays representing country code and currency code should return an object where the keys are country code values are currency code",()=>{ + const countryCurrencyPairs = [['IND', 'INR'], ['US', 'USD'], ['UK', 'GBR'], ['CA','CAD'] ]; + expect(createLookup(countryCurrencyPairs)).toEqual({ + IND: "INR", + US: "USD", + UK: "GBR", + CA: "CAD", + }); +}) /* Create a lookup object of key value pairs from an array of code pairs diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index 45ec4e5f3..118a27b53 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -5,8 +5,10 @@ function parseQueryString(queryString) { } const keyValuePairs = queryString.split("&"); - for (const pair of keyValuePairs) { - const [key, value] = pair.split("="); + for (const item of keyValuePairs) { + const pair = item.split("="); + const key = pair.shift(); + const value = pair.join("="); queryParams[key] = value; } diff --git a/Sprint-2/implement/querystring.test.js b/Sprint-2/implement/querystring.test.js index 3e218b789..c5681bec4 100644 --- a/Sprint-2/implement/querystring.test.js +++ b/Sprint-2/implement/querystring.test.js @@ -10,3 +10,18 @@ test("parses querystring values containing =", () => { "equation": "x=y+1", }); }); +test("An empty string should return an empty object",()=>{ + expect(parseQueryString("")).toEqual({}); +}); +test("parses querystring parameters with an empty value",()=>{ + expect(parseQueryString("name=")).toEqual({name :""}); +}); +test("handles querystring parameters that have no = sign",()=>{ + expect(parseQueryString("flag")).toEqual({flag:""}) +}); +test("parses querystring values containing multiple = characters",()=>{ + expect(parseQueryString("token=a=b=c=d")).toEqual({token:"a=b=c=d"}); +}); +test("handles multiple querystring parameters when one value contains =",()=>{ + expect(parseQueryString("a=1&equation=x=y+1")).toEqual({a:"1", equation:"x=y+1"}); +}); diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index f47321812..88ff23bb1 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -1,3 +1,18 @@ -function tally() {} +function tally(arr) { + const object = {}; + if(!Array.isArray(arr)) + { + throw new Error("Invalid input: tally expects an array"); + } + if(arr.length === 0) + { + return object; + } + arr.forEach(ele =>{ + object[ele] =(object[ele] || 0) + 1; + + }); + return object; +} module.exports = tally; diff --git a/Sprint-2/implement/tally.test.js b/Sprint-2/implement/tally.test.js index 2ceffa8dd..691b622be 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -13,6 +13,15 @@ const tally = require("./tally.js"); * tally(['a', 'a', 'a']), target output: { a: 3 } * tally(['a', 'a', 'b', 'c']), target output: { a : 2, b: 1, c: 1 } */ +test("throws an error when the input is not an array", ()=>{ + expect(()=>tally("hi")).toThrow(); +}); +test("returns an empty object when the input array is empty",()=>{ + expect(tally([])).toEqual({}); +}); +test("returns the count of each unique item in the array", ()=>{ + expect(tally(['a','b','a','c','b','a'])).toEqual({a:3,b:2,c:1}) +}); // Acceptance criteria: diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index bb353fb1f..0cdc4da5e 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -9,21 +9,28 @@ function invert(obj) { const invertedObj = {}; - for (const [key, value] of Object.entries(obj)) { - invertedObj.key = value; + for (const [value, key] of Object.entries(obj)) { + invertedObj[key] = value; } return invertedObj; } +module.exports = invert; // 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 } +//{key:1, key : 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? +// Object.entries() returns an array of [key, value] pairs from an object. It is used here to loop through the object and access both the key and value in each iteration. // d) Explain why the current return value is different from the target output +// The return value is different because the program uses dot notation with a variable instead of bracket notation. +// Also, the object needs to be inverted, so the key and value must be swapped when iterating through the entries. // e) Fix the implementation of invert (and write tests to prove it's fixed!) diff --git a/Sprint-2/interpret/invert.test.js b/Sprint-2/interpret/invert.test.js new file mode 100644 index 000000000..a5d0a564b --- /dev/null +++ b/Sprint-2/interpret/invert.test.js @@ -0,0 +1,10 @@ +const invert = require("./invert"); + +test("returns an object with the key and value swapped when given a single key-value pair", ()=>{ + expect(invert({a:1})).toEqual({'1':'a'}) +}); + +test("returns an object with all keys and values swapped for multiple key-value pairs",()=>{ + + expect(invert({a:1, b:2})).toEqual({'1':'a','2':'b'}) +}); \ No newline at end of file From 9c0eeb1b693463a8461ef215c6d18083340ab055 Mon Sep 17 00:00:00 2001 From: Arunkumar Akilan Date: Sun, 22 Mar 2026 15:52:14 +0000 Subject: [PATCH 2/5] add div for styling --- Sprint-3/quote-generator/index.html | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Sprint-3/quote-generator/index.html b/Sprint-3/quote-generator/index.html index 30b434bcf..4e2ccc9a2 100644 --- a/Sprint-3/quote-generator/index.html +++ b/Sprint-3/quote-generator/index.html @@ -3,13 +3,15 @@ - Title here - + Quote generator app + -

hello there

-

-

+
+

+

+
+ From 333c080c06c2d2cea8534295a1bf13b6314ec49c Mon Sep 17 00:00:00 2001 From: Arunkumar Akilan Date: Sun, 22 Mar 2026 15:53:35 +0000 Subject: [PATCH 3/5] feat: connect quotes array to DOM and update UI dynamically --- Sprint-3/quote-generator/quotes.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Sprint-3/quote-generator/quotes.js b/Sprint-3/quote-generator/quotes.js index 4a4d04b72..e2b65e00d 100644 --- a/Sprint-3/quote-generator/quotes.js +++ b/Sprint-3/quote-generator/quotes.js @@ -490,4 +490,19 @@ const quotes = [ }, ]; -// call pickFromArray with the quotes array to check you get a random quote +function quoteGenerator() +{ + +let randomQuote = pickFromArray(quotes); +let accessQuote = document.querySelector("#quote"); +accessQuote.textContent = randomQuote.quote; +let accessAuthor = document.querySelector("#author"); +accessAuthor.textContent = randomQuote.author; + +} + +quoteGenerator(); +let newQuote = document.querySelector("#new-quote"); +newQuote.addEventListener("click",quoteGenerator) + + From 9197a515b263621dd65c3737ec80b3ffbf6d09bd Mon Sep 17 00:00:00 2001 From: Arunkumar Akilan Date: Sun, 22 Mar 2026 15:54:32 +0000 Subject: [PATCH 4/5] feat: add layout and styling to match quote generator design --- Sprint-3/quote-generator/style.css | 37 +++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/Sprint-3/quote-generator/style.css b/Sprint-3/quote-generator/style.css index 63cedf2d2..941a22aa4 100644 --- a/Sprint-3/quote-generator/style.css +++ b/Sprint-3/quote-generator/style.css @@ -1 +1,36 @@ -/** Write your CSS in here **/ +body{ + background-color:orange; + padding: 200px; + padding-right: 300px; + text-align: center; + font-weight: bold; + font-family:'Times New Roman', Times, serif; + font-size: 20px; +} +#quote{ + color:orange; + padding: 20px; + font-size: 30px; +} +#author{ + color:orange; + text-align: right; + font-size: 25px; + margin-top: 20px; +} +#card{ + background-color: white; + padding: 40px; + margin-top: 20px; +} +#new-quote{ + background-color: orange; + color: white; + display: block; + margin-left: auto; + margin-top: 10px; + padding: 10px 20px; + border: none; + font-size: 20px; + cursor: pointer; +} \ No newline at end of file From 48423a23642dd32cf2059ccb83f9d37646b2fef1 Mon Sep 17 00:00:00 2001 From: Arunkumar Akilan Date: Sun, 22 Mar 2026 15:56:05 +0000 Subject: [PATCH 5/5] feat: implement quote generator to pass existing tests --- Sprint-3/quote-generator/quotes.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-3/quote-generator/quotes.test.js b/Sprint-3/quote-generator/quotes.test.js index f7b128bf7..a288e3247 100644 --- a/Sprint-3/quote-generator/quotes.test.js +++ b/Sprint-3/quote-generator/quotes.test.js @@ -75,3 +75,5 @@ describe("Quote generator", () => { expect(authorP).toHaveTextContent("Rosa Parks"); }); }); + +//completed \ No newline at end of file