From b268ce7b8a2720142820bc4b8507a6e344038eed Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Tue, 7 Jul 2026 16:23:53 +0100 Subject: [PATCH 01/16] implemented getAngleType function --- .../implement/1-get-angle-type.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index 9e05a871e2..ea34ffe3cf 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -15,7 +15,19 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - // TODO: Implement this function + if (angle > 0 && angle < 90) { + return "Acute angle"; + } else if (angle === 90) { + return "Right angle"; + } else if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } else if (angle === 180) { + return "Straight angle"; + } else if (angle > 180 && angle < 360) { + return "Reflex angle"; + } else { + return "Invalid angle"; + } } // The line below allows us to load the getAngleType function into tests in other files. From 3fd0aaacd339d9c356fcb98a1ec2c0cdf842c5b8 Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Wed, 8 Jul 2026 21:58:04 +0100 Subject: [PATCH 02/16] added test to ensure the function works as it should --- .../implement/1-get-angle-type.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index ea34ffe3cf..d3273c6350 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -46,4 +46,30 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles const right = getAngleType(90); +const acute = getAngleType(66); +const obtuse = getAngleType(109); +const straight = getAngleType(180); +const reflex = getAngleType(222); +const invalid = getAngleType(366); +const boundary = getAngleType(0); +const invalidBoundary = getAngleType(360) +const acuteBoundary = getAngleType(1) +const acuteSecondBoundary = getAngleType(89) +const obtuseBoundary = getAngleType(91) +const reflexBoundary = getAngleType(181) + + + assertEquals(right, "Right angle"); +assertEquals(acute, "Acute angle"); +assertEquals(obtuse, "Obtuse angle"); +assertEquals(straight, "Straight angle"); +assertEquals(reflex, "Reflex angle") +assertEquals(invalid, "Invalid angle") +assertEquals(invalidBoundary, "Invalid angle") +assertEquals(acuteBoundary, "Acute angle") +assertEquals(acuteSecondBoundary, "Acute angle") +assertEquals(obtuseBoundary, "Obtuse angle") +assertEquals(reflexBoundary, "Reflex angle") + + From 5fce59103af6a2c573160177c18e4152a16a828e Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Wed, 8 Jul 2026 22:27:26 +0100 Subject: [PATCH 03/16] implemented the function and wrote test cases --- .../implement/2-is-proper-fraction.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index 970cb9b641..bc994aa83a 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -11,7 +11,11 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + if (numerator <= denominator && numerator > 0) { + return true; + } else { + return false; + } } // The line below allows us to load the isProperFraction function into tests in other files. @@ -31,3 +35,10 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(0, 4), false); +assertEquals(isProperFraction(5, 5), true); +assertEquals(isProperFraction(-8, 2), false); +assertEquals(isProperFraction(4, 0), false); +assertEquals(isProperFraction(0, 0), false); +assertEquals(isProperFraction(-2, -2), false) + From baf0b786a9daa3881e3d3e1d76b7f0c0d0199621 Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Sat, 11 Jul 2026 00:19:50 +0100 Subject: [PATCH 04/16] implemented function and added new test cases --- .../implement/3-get-card-value.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index ff5c532e1d..caf88928b6 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -22,7 +22,16 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + let removeSuit = card.slice(0, -1); + if (removeSuit === "A") { + return 11; + } else if (removeSuit === "J" || removeSuit === "Q" ||removeSuit === "K") { + return 10; + } else if (removeSuit > 1 && removeSuit < 11) { + return Number(removeSuit); + } else { + throw new Error("Parameter is not a number!") + } } // The line below allows us to load the getCardValue function into tests in other files. @@ -40,6 +49,11 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. // Examples: assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("A♠"), 11); +assertEquals(getCardValue("J♦"), 10); +assertEquals(getCardValue("7♥"), 7); +assertEquals(getCardValue("7♥"), "A"); +assertEquals(getCardValue("8♥"), 8); // Handling invalid cards try { From c175d1b47ed73e099093c8cb8e80391567ce967a Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Sat, 11 Jul 2026 14:17:39 +0100 Subject: [PATCH 05/16] added test cases to check the function --- .../1-get-angle-type.test.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js index d777f348d3..b26253f729 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js @@ -14,7 +14,33 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle +test(`should return "Right angle" when (angle = 90)`, () => { + // Test various acute angles, including boundary cases + expect(getAngleType(90)).toEqual("Right angle"); +}); // Case 3: Obtuse angles +test(`should return "Obtuse angle" when (angle < 180, angle > 90)`, () => { + // Test various acute angles, including boundary cases + expect(getAngleType(91)).toEqual("Obtuse angle"); + expect(getAngleType(179)).toEqual("Obtuse angle"); + expect(getAngleType(99)).toEqual("Obtuse angle"); +}); // Case 4: Straight angle +test(`should return "Straight angle" when (angle = 180)`, () => { + // Test various acute angles, including boundary cases + expect(getAngleType(180)).toEqual("Straight angle"); +}); // Case 5: Reflex angles +test(`should return "Reflex angle" when (angle < 360, angle > 180)`, () => { + // Test various acute angles, including boundary cases + expect(getAngleType(189)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); + expect(getAngleType(199)).toEqual("Reflex angle"); +}); // Case 6: Invalid angles +test(`should return "Invalid angle" when (angle > 361, angle < 0)`, () => { + // Test various acute angles, including boundary cases + expect(getAngleType(505)).toEqual("Invalid angle"); + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(699)).toEqual("Invalid angle"); +}); \ No newline at end of file From e050e1b6c5ef34c29a0d6ca50358ccbc265c6886 Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Sat, 11 Jul 2026 14:22:30 +0100 Subject: [PATCH 06/16] added new test cases to check the function --- .../rewrite-tests-with-jest/2-is-proper-fraction.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js index 7f087b2ba1..2054882b8a 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js @@ -7,4 +7,11 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); // Special case: numerator is zero test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); + expect(isProperFraction(2, 4)).toEqual(true); + expect(isProperFraction(5, -2)).toEqual(false); + expect(isProperFraction(3, 3)).toEqual(true); + expect(isProperFraction(-1, 0)).toEqual(false); + expect(isProperFraction(5, 10)).toEqual(true); + expect(isProperFraction(12, 4)).toEqual(false); + expect(isProperFraction(2, 2)).toEqual(true); }); From 86587307054fe576fde6e1f2308cffc14c932ffe Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Sat, 11 Jul 2026 15:18:07 +0100 Subject: [PATCH 07/16] updated tests cases to check more error cases --- .../implement/3-get-card-value.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index caf88928b6..aadcdf4352 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -52,13 +52,12 @@ assertEquals(getCardValue("9♠"), 9); assertEquals(getCardValue("A♠"), 11); assertEquals(getCardValue("J♦"), 10); assertEquals(getCardValue("7♥"), 7); -assertEquals(getCardValue("7♥"), "A"); +assertEquals(getCardValue("A♥"), 11); assertEquals(getCardValue("8♥"), 8); // Handling invalid cards try { getCardValue("invalid"); - // This line will not be reached if an error is thrown as expected console.error("Error was not thrown for invalid card 😢"); } catch (e) { @@ -66,3 +65,10 @@ try { } // What other invalid card cases can you think of? +try { + getCardValue("15♥"); + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} From 5a46aac5403e6760918b15ac20232bda455a7dba Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Sat, 11 Jul 2026 15:18:49 +0100 Subject: [PATCH 08/16] updated jest test cases breaking it down to individual cases --- .../2-is-proper-fraction.test.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js index 2054882b8a..1ec2823d82 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js @@ -7,11 +7,19 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); // Special case: numerator is zero test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); +}); +test(`should return true when denominator is smaller or equal to the numerator`,() =>{ expect(isProperFraction(2, 4)).toEqual(true); - expect(isProperFraction(5, -2)).toEqual(false); expect(isProperFraction(3, 3)).toEqual(true); - expect(isProperFraction(-1, 0)).toEqual(false); expect(isProperFraction(5, 10)).toEqual(true); - expect(isProperFraction(12, 4)).toEqual(false); expect(isProperFraction(2, 2)).toEqual(true); }); + +test(`should return false when denominator is bigger than the numerator`, () => { + expect(isProperFraction(5, -2)).toEqual(false); + expect(isProperFraction(-1, 0)).toEqual(false); + expect(isProperFraction(12, 4)).toEqual(false); + +}); + + From 9173d38e11cd2a5c6b4848a048de82014e05a108 Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Sat, 11 Jul 2026 16:31:53 +0100 Subject: [PATCH 09/16] figured out how to debug jest and use the toThrow for an error message --- .../implement/3-get-card-value.js | 3 +- .../3-get-card-value.test.js | 29 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index aadcdf4352..7d38831bb8 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -30,7 +30,7 @@ function getCardValue(card) { } else if (removeSuit > 1 && removeSuit < 11) { return Number(removeSuit); } else { - throw new Error("Parameter is not a number!") + throw new Error("Error") } } @@ -72,3 +72,4 @@ try { } catch (e) { console.log("Error thrown for invalid card 🎉"); } + diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js index cf7f9dae2e..22a61f8698 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js @@ -9,6 +9,29 @@ test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); +test(`Should return 10 when given a Joker card`, () => { + expect(getCardValue("J♥")).toEqual(10); +}); + +test(`Should return 2 when given the 2 card`, () => { + expect(getCardValue("2♠")).toEqual(2); +}); + +test(`Should return 10 when given a King card`, () => { + expect(getCardValue("K♠")).toEqual(10); +}); + +test(`Should return 5 when given the 5 card`, () => { + expect(getCardValue("5♠")).toEqual(5); +}); + +test(`Should return 8 when gine the 8 card`, () => { + expect(getCardValue("8♠")).toEqual(8); +}); + +test(`Should return 10 when given the Queen card`, () => { + expect(getCardValue("Q♠")).toEqual(10); +}); // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) // Face Cards (J, Q, K) @@ -17,4 +40,8 @@ test(`Should return 11 when given an ace card`, () => { // To learn how to test whether a function throws an error as expected in Jest, // please refer to the Jest documentation: // https://jestjs.io/docs/expect#tothrowerror - +test(`Should not return any card should throw an error message`, () => { + expect(() => { + getCardValue("QQ♥"); + }).toThrow(); +}); From 162fe578e3dc018e54b8759a28ba0825d98bad0c Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Mon, 13 Jul 2026 18:02:18 +0100 Subject: [PATCH 10/16] implemented function and added test cases to check if the function is working correctly --- Sprint-3/2-practice-tdd/count.js | 9 ++++++++- Sprint-3/2-practice-tdd/count.test.js | 28 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..39f0058613 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,12 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + let countCharacter = 0; + for (let i = 0; i < stringOfCharacters.length; i++){ + if (stringOfCharacters.charAt(i) === findCharacter){ + countCharacter += 1; + } + } + return countCharacter } + module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf7..969b52b2d3 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -22,3 +22,31 @@ test("should count multiple occurrences of a character", () => { // And a character `char` that does not exist within `str`. // When the function is called with these inputs, // Then it should return 0, indicating that no occurrences of `char` were found. + +test("should count multiple occurrences of a character", () => { + const str = "banana"; + const char = "n"; + const count = countChar(str, char); + expect(count).toEqual(2); +}); + +test("should count multiple occurrences of a character", () => { + const str = "appleTree"; + const char = "e"; + const count = countChar(str, char); + expect(count).toEqual(3); +}); + +test("should count multiple occurrences of a character", () => { + const str = "strawberry"; + const char = "r"; + const count = countChar(str, char); + expect(count).toEqual(3); +}); + +test("should count multiple occurrences of a character", () => { + const str = "ghost"; + const char = "o"; + const count = countChar(str, char); + expect(count).toEqual(1); +}); \ No newline at end of file From 1e8cdc06bae99a44b1da4c308ab8506176dea023 Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Mon, 13 Jul 2026 18:56:21 +0100 Subject: [PATCH 11/16] implemented code and updated test cases --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 10 ++++++- .../2-practice-tdd/get-ordinal-number.test.js | 27 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db13..71cea0a015 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,13 @@ function getOrdinalNumber(num) { - return "1st"; + if (num % 10 === 1 && num % 100 !== 11) { + return `${num}st`; + } else if (num % 10 === 2 && num % 100 !== 12 ) { + return `${num}nd`; + } else if (num % 10 === 3 && num % 100 !== 13) { + return `${num}rd`; + } else { + return `${num}th`; + } } module.exports = getOrdinalNumber; diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js index adfa58560f..9f31ab1b9c 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -17,4 +17,31 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(1)).toEqual("1st"); expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(131)).toEqual("131st"); + expect(getOrdinalNumber(1101)).toEqual("1101st") +}); + +test("should append 'nd' for numbers ending with 2, except those ending with 12", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(22)).toEqual("22nd"); + expect(getOrdinalNumber(132)).toEqual("132nd"); + expect(getOrdinalNumber(22222)).toEqual("22222nd") +}); + +test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(23)).toEqual("23rd"); + expect(getOrdinalNumber(133)).toEqual("133rd"); + expect(getOrdinalNumber(33333)).toEqual("33333rd") +}); + +test("should append 'th' for numbers ending with 11, 12, 13", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); + expect(getOrdinalNumber(111)).toEqual("111th"); + expect(getOrdinalNumber(112)).toEqual("112th"); + expect(getOrdinalNumber(113)).toEqual("113th"); + expect(getOrdinalNumber(11111)).toEqual("11111th") + expect(getOrdinalNumber(11112)).toEqual("11112th") + expect(getOrdinalNumber(11113)).toEqual("11113th") }); From 41df188a5342a3e2ad4ad07e808397ed7b3809f2 Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Mon, 13 Jul 2026 19:32:57 +0100 Subject: [PATCH 12/16] implemented repeatStr function and added test cases --- Sprint-3/2-practice-tdd/repeat-str.js | 14 ++++++++++---- Sprint-3/2-practice-tdd/repeat-str.test.js | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 2af0a2cea7..55b48ee389 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,7 +1,13 @@ -function repeatStr() { - // Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat). - // The goal is to re-implement that function, not to use it. - return "hellohellohello"; +function repeatStr(str, count) { + if (count < 0) { + throw new Error("Error"); + } + + let repeatedString = ""; + for (let i = 0; i < count; i++) { + repeatedString += str; + } + return repeatedString; } module.exports = repeatStr; diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index a3fc1196c4..4b5c3d17c0 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -20,13 +20,33 @@ test("should repeat the string count times", () => { // Given a target string `str` and a `count` equal to 1, // When the repeatStr function is called with these inputs, // Then it should return the original `str` without repetition. +test("should repeat the string count times", () => { + const str = "what"; + const count = 1; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("what"); +}); // Case: Handle count of 0: // Given a target string `str` and a `count` equal to 0, // When the repeatStr function is called with these inputs, // Then it should return an empty string. +test("should return an empty string", () => { + const str = "hello"; + const count = 0; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual(""); +}); + // Case: Handle negative count: // Given a target string `str` and a negative integer `count`, // When the repeatStr function is called with these inputs, // Then it should throw an error, as negative counts are not valid. +test("should throw an error message", () => { + const str = "hello"; + const count = -3; + expect(() => { + repeatStr(str, count); + }).toThrow(); +}); From d5d63e8db2032d6bdbf80e58194538cf61ef430e Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Mon, 13 Jul 2026 19:54:23 +0100 Subject: [PATCH 13/16] completed exercise and commented out the redundant lines --- Sprint-3/3-dead-code/exercise-1.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js index 4d09f15fa9..6b3f3201cc 100644 --- a/Sprint-3/3-dead-code/exercise-1.js +++ b/Sprint-3/3-dead-code/exercise-1.js @@ -5,9 +5,11 @@ let testName = "Jerry"; const greeting = "hello"; function sayHello(greeting, name) { - const greetingStr = greeting + ", " + name + "!"; + //const greetingStr = greeting + ", " + name + "!"; + // - removing this line as this is redundant code and duplicated inside the return return `${greeting}, ${name}!`; - console.log(greetingStr); + //console.log(greetingStr); + // - removing this line because after return the console.log will not execute } testName = "Aman"; From feb8f9020551ee11f7048779b177c7403cc9cc11 Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Mon, 13 Jul 2026 21:25:17 +0100 Subject: [PATCH 14/16] updated function to eliminate incorrect values --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 5 +++++ .../2-practice-tdd/get-ordinal-number.test.js | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index 71cea0a015..43e1a8f028 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,4 +1,8 @@ function getOrdinalNumber(num) { + if ( typeof num !== "number" ){ + throw new Error('Not a number') + } + if (num % 10 === 1 && num % 100 !== 11) { return `${num}st`; } else if (num % 10 === 2 && num % 100 !== 12 ) { @@ -6,6 +10,7 @@ function getOrdinalNumber(num) { } else if (num % 10 === 3 && num % 100 !== 13) { return `${num}rd`; } else { + return `${num}th`; } } diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js index 9f31ab1b9c..42bfaa35bd 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -17,21 +17,21 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(1)).toEqual("1st"); expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(131)).toEqual("131st"); - expect(getOrdinalNumber(1101)).toEqual("1101st") + expect(getOrdinalNumber(1101)).toEqual("1101st"); }); test("should append 'nd' for numbers ending with 2, except those ending with 12", () => { expect(getOrdinalNumber(2)).toEqual("2nd"); expect(getOrdinalNumber(22)).toEqual("22nd"); expect(getOrdinalNumber(132)).toEqual("132nd"); - expect(getOrdinalNumber(22222)).toEqual("22222nd") + expect(getOrdinalNumber(22222)).toEqual("22222nd"); }); test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { expect(getOrdinalNumber(3)).toEqual("3rd"); expect(getOrdinalNumber(23)).toEqual("23rd"); expect(getOrdinalNumber(133)).toEqual("133rd"); - expect(getOrdinalNumber(33333)).toEqual("33333rd") + expect(getOrdinalNumber(33333)).toEqual("33333rd"); }); test("should append 'th' for numbers ending with 11, 12, 13", () => { @@ -41,7 +41,13 @@ test("should append 'th' for numbers ending with 11, 12, 13", () => { expect(getOrdinalNumber(111)).toEqual("111th"); expect(getOrdinalNumber(112)).toEqual("112th"); expect(getOrdinalNumber(113)).toEqual("113th"); - expect(getOrdinalNumber(11111)).toEqual("11111th") - expect(getOrdinalNumber(11112)).toEqual("11112th") - expect(getOrdinalNumber(11113)).toEqual("11113th") + expect(getOrdinalNumber(11111)).toEqual("11111th"); + expect(getOrdinalNumber(11112)).toEqual("11112th"); + expect(getOrdinalNumber(11113)).toEqual("11113th"); +}); + +test("should throw an error message", () => { + expect(() => { + getOrdinalNumber("Hello"); + }).toThrow(); }); From 8f64420fcbf9f59e4fd5927cd6f5a9ea3711148e Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Mon, 13 Jul 2026 21:31:28 +0100 Subject: [PATCH 15/16] removed the redundant line of codes and the unused functions --- Sprint-3/3-dead-code/exercise-2.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js index 56d7887c4c..e0468f822a 100644 --- a/Sprint-3/3-dead-code/exercise-2.js +++ b/Sprint-3/3-dead-code/exercise-2.js @@ -2,12 +2,15 @@ // The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable. const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; -const capitalisedPets = pets.map((pet) => pet.toUpperCase()); +// const capitalisedPets = pets.map((pet) => pet.toUpperCase()); +// -- Removing this because countAndCapitalisePets already capitalises each pet. --redundant code const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); -function logPets(petsArr) { - petsArr.forEach((pet) => console.log(pet)); -} +// function logPets(petsArr) { +// petsArr.forEach((pet) => console.log(pet)); +// } + +// --logPets does not effect the final console.log - unused code function countAndCapitalisePets(petsArr) { const petCount = {}; From 6720ac57d971adb570e48c8a104550334395d295 Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Wed, 15 Jul 2026 22:09:23 +0100 Subject: [PATCH 16/16] added explanations for while loop questions --- Sprint-3/4-stretch/find.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-3/4-stretch/find.js b/Sprint-3/4-stretch/find.js index c7e79a2f21..5ecb44f994 100644 --- a/Sprint-3/4-stretch/find.js +++ b/Sprint-3/4-stretch/find.js @@ -20,6 +20,10 @@ console.log(find("code your future", "z")); // Pay particular attention to the following: // a) How the index variable updates during the call to find +//--the index variable will start at 0, and this will increase by +1 each time the loop runs by using index++ to loop around the string, checking each index inside the string one by one // b) What is the if statement used to check +//--the if statement checks the current str index if it's equal to char, to find the character we are searching for // c) Why is index++ being used? +//--the index++ increases the index by 1 each time so the function can check every character in the string one by one. // d) What is the condition index < str.length used for? +//--this condition will checks the index has not reached the end of the string. Once the index is equal to the string length, the loop stops