From 1b080b7f396571a3ee9a67383716249723f12bd6 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sat, 14 Mar 2026 12:50:38 +0000 Subject: [PATCH 01/21] I implemented the getAngleType function using if.....elseif --- .../implement/1-get-angle-type.js | 17 +++++++++++++++++ 1 file changed, 17 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 9e05a871e2..711cbc115b 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,6 +15,23 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { + if (angle > 0 && angle < 90) { + return 'Acute'; + } + else if (angle===90) { + return 'Right'; + } + else if ( angle > 90 && angle < 180){ + return 'Obtuse'; + } + else if( angle === 180) { + return ' Stright'; + } + else if (angle > 180 && angle < 360) { + return 'reflex'; + } + else {return 'Invalid';} + // TODO: Implement this function } From 95c31a0f6828cb19ae29cf0ace53570143b5c969 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sat, 14 Mar 2026 13:21:12 +0000 Subject: [PATCH 02/21] I wrote a test to cover all cases include boundary and out of the range values using assert function --- .../implement/1-get-angle-type.js | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) 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 711cbc115b..1151ef8c4a 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 @@ -16,21 +16,21 @@ function getAngleType(angle) { if (angle > 0 && angle < 90) { - return 'Acute'; + return 'Acute angle'; } else if (angle===90) { - return 'Right'; + return 'Right angle'; } else if ( angle > 90 && angle < 180){ - return 'Obtuse'; + return 'Obtuse angle'; } else if( angle === 180) { - return ' Stright'; + return ' Stright angle'; } else if (angle > 180 && angle < 360) { - return 'reflex'; + return 'reflex angle'; } - else {return 'Invalid';} + else {return 'Invalid angle';} // TODO: Implement this function } @@ -52,3 +52,31 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); +// assertEquals (getAngleType(90), "Right angle"); + +const acute = getAngleType(45); +assertEquals(acute, "Acute angle"); +// assertEqual (getAngleType(45),"Acute angle"); + +const obtuse = getAngleType(120); +assertEquals(obtuse, "Obtuse angle"); +// assertEqual (getAngleType(120),"Obtuse angle"); + +const stright = getAngleType(180); +assertEquals(stright, "Stright angle"); +// assertEqual (getAngleType(180),"Stright angle"); +const reflex = getAngleType(270); +assertEquals(reflex, "Reflex angle"); +// assertEqual (getAngleType(270),"Reflex angle"); + +const invalid = getAngleType(360); +assertEquals(invalid, "Invalid angle"); +// assertEqual (getAngleType(360),"Invalid angle"); +//Boundary cases + const invalid = getAngleType(0); +assertEquals(invalid, "Invalid angle"); +// assertEqual (getAngleType(0),"Invalid angle"); +//Outside range +const invalid = getAngleType(-10 , 400); +assertEquals(invalid, "Invalid angle"); +// assertEqual (getAngleType(-10 , 400),"Invalid angle"); \ No newline at end of file From 605172201c06d641a97b050ce24c6261d7f73008 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sat, 14 Mar 2026 14:02:08 +0000 Subject: [PATCH 03/21] I implemented the isProperFraction function using if...else statement. --- .../implement/1-get-angle-type.js | 52 +++++++++---------- .../implement/2-is-proper-fraction.js | 5 ++ 2 files changed, 31 insertions(+), 26 deletions(-) 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 1151ef8c4a..72435f8513 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 @@ -25,10 +25,10 @@ function getAngleType(angle) { return 'Obtuse angle'; } else if( angle === 180) { - return ' Stright angle'; + return 'Stright angle'; } else if (angle > 180 && angle < 360) { - return 'reflex angle'; + return 'Reflex angle'; } else {return 'Invalid angle';} @@ -50,33 +50,33 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles -const right = getAngleType(90); -assertEquals(right, "Right angle"); -// assertEquals (getAngleType(90), "Right angle"); +// const right = getAngleType(90); +// assertEquals(right, "Right angle"); +assertEquals (getAngleType(90), "Right angle"); -const acute = getAngleType(45); -assertEquals(acute, "Acute angle"); -// assertEqual (getAngleType(45),"Acute angle"); +// const acute = getAngleType(45); +// assertEquals(acute, "Acute angle"); +assertEquals (getAngleType(45),"Acute angle"); -const obtuse = getAngleType(120); -assertEquals(obtuse, "Obtuse angle"); -// assertEqual (getAngleType(120),"Obtuse angle"); +// const obtuse = getAngleType(120); +// assertEquals(obtuse, "Obtuse angle"); +assertEquals (getAngleType(120),"Obtuse angle"); -const stright = getAngleType(180); -assertEquals(stright, "Stright angle"); -// assertEqual (getAngleType(180),"Stright angle"); -const reflex = getAngleType(270); -assertEquals(reflex, "Reflex angle"); -// assertEqual (getAngleType(270),"Reflex angle"); +// const stright = getAngleType(180); +// assertEquals(stright, "Stright angle"); +assertEquals (getAngleType(180),"Stright angle"); +// const reflex = getAngleType(270); +// assertEquals(reflex, "Reflex angle"); +assertEquals (getAngleType(270),"Reflex angle"); -const invalid = getAngleType(360); -assertEquals(invalid, "Invalid angle"); -// assertEqual (getAngleType(360),"Invalid angle"); +// const invalid = getAngleType(360); +// assertEquals(invalid, "Invalid angle"); +assertEquals (getAngleType(360),"Invalid angle"); //Boundary cases - const invalid = getAngleType(0); -assertEquals(invalid, "Invalid angle"); -// assertEqual (getAngleType(0),"Invalid angle"); +// const invalid = getAngleType(0); +// assertEquals(invalid, "Invalid angle"); +assertEquals (getAngleType(0),"Invalid angle"); //Outside range -const invalid = getAngleType(-10 , 400); -assertEquals(invalid, "Invalid angle"); -// assertEqual (getAngleType(-10 , 400),"Invalid angle"); \ No newline at end of file +// const invalid = getAngleType(-10 , 400); +// assertEquals(invalid, "Invalid angle"); +assertEquals (getAngleType(-10 , 400),"Invalid angle"); \ No newline at end of file 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..e4cd408eeb 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,6 +11,11 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { + if( numerator < denominator) { + return true; + } + else {return false; } + // TODO: Implement this function } From ab68b5a4b0e7d0b7aac3f645b7d82d9652f6f49e Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sat, 14 Mar 2026 14:10:18 +0000 Subject: [PATCH 04/21] I wrote case tests to cover proper and inproper fractions include negative and equal numbers. --- .../implement/2-is-proper-fraction.js | 9 +++++++++ 1 file changed, 9 insertions(+) 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 e4cd408eeb..b31b38b23e 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 @@ -36,3 +36,12 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +// inproper fraction: +assertEquals (isProperFraction(5, 3), false ); + +// equal numbers +assertEquals (isProperFraction(4, 4), false ); + +// negative numbers +assertEquals (isProperFraction(-2, 4), true ); +assertEquals (isProperFraction(5, -4), false ); From 573b24fcf56c7a041e23e77d7019f96e2ae238fd Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sat, 14 Mar 2026 14:36:14 +0000 Subject: [PATCH 05/21] I implimented the getCardVlue function, wrote assert tests and executed the code ensuring that all tests passed. --- .../implement/3-get-card-value.js | 54 ++++++++++++++++++- 1 file changed, 53 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 c7559e787e..76944e8e99 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,9 +22,31 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + const suit = card.slice(-1); + const rank = card.slice(0, -1); + + if (suit !== "♠" && suit !== "♥" && suit !== "♦" && suit !== "♣") { + throw new Error("Invalid card"); + } + + if (rank === "A") { + return 11; + } + + if (rank === "J" || rank === "Q" || rank === "K") { + return 10; + } + + if (rank >= "2" && rank <= "10") { + return Number(rank); + } + + throw new Error("Invalid card"); } + // TODO: Implement this function + + // The line below allows us to load the getCardValue function into tests in other files. // This will be useful in the "rewrite tests with jest" step. module.exports = getCardValue; @@ -40,6 +62,16 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. // Examples: assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("2♠"), 2); +assertEquals(getCardValue("10♦"), 10); + +// Face cards +assertEquals(getCardValue("J♣"), 10); +assertEquals(getCardValue("Q♥"), 10); +assertEquals(getCardValue("K♦"), 10); + +// Ace +assertEquals(getCardValue("A♠"), 11); // Handling invalid cards try { @@ -49,4 +81,24 @@ try { console.error("Error was not thrown for invalid card"); } catch (e) {} + // What other invalid card cases can you think of? +try { + getCardValue("1♠"); // invalid rank + console.error("Error was not thrown for invalid card"); +} catch (e) {} + +try { + getCardValue("B♣"); // invalid rank + console.error("Error was not thrown for invalid card"); +} catch (e) {} + +try { + getCardValue("10?"); // invalid suit + console.error("Error was not thrown for invalid card"); +} catch (e) {} + +try { + getCardValue("Z♠"); // invalid rank + console.error("Error was not thrown for invalid card"); +} catch (e) {} \ No newline at end of file From f0d0324e39e4b972216d94f4666d15f4d40375bc Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sat, 14 Mar 2026 14:49:24 +0000 Subject: [PATCH 06/21] wrapped all invalid cards in try-catch --- .../implement/3-get-card-value.js | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 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 76944e8e99..7194d4430a 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 @@ -83,22 +83,13 @@ try { // What other invalid card cases can you think of? -try { - getCardValue("1♠"); // invalid rank - console.error("Error was not thrown for invalid card"); -} catch (e) {} - -try { - getCardValue("B♣"); // invalid rank - console.error("Error was not thrown for invalid card"); -} catch (e) {} -try { - getCardValue("10?"); // invalid suit - console.error("Error was not thrown for invalid card"); -} catch (e) {} - -try { - getCardValue("Z♠"); // invalid rank - console.error("Error was not thrown for invalid card"); -} catch (e) {} \ No newline at end of file +const invalidCards = ["invalid", "1♠", "B♣", "10?", "Z♠"]; +for (const card of invalidCards) { + try { + getCardValue(card); + console.error(`Error was not thrown for invalid card: ${card}`); + } catch (e) { + // Expected error, do nothing + } +} From 0ab5c67652a7041ded3be657cb4d0795a6c53c21 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sat, 14 Mar 2026 15:14:30 +0000 Subject: [PATCH 07/21] I wrote tests in jest syntax to cover all the angle cases including bundary and invalid cases. --- .../1-get-angle-type.test.js | 28 +++++++++++++++++++ 1 file changed, 28 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..d934e54d99 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,35 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle +test(`should return "Right angle" when (angle=== 90)`, () => { + expect(getAngleType(90)).toEqual("Right angle"); +}); + // Case 3: Obtuse angles +test (`should return "Obtuse angle" when (90 < angle < 180)` ,() =>{ + + expect(getAngleType(95)).toEqual("Obtuse angle"); + expect(getAngleType(120)).toEqual("Obtuse angle"); + expect(getAngleType(100)).toEqual("Obtuse angle"); +}); + // Case 4: Straight angle +test (`should return "Straight angle" when ( angle === 180)` ,() =>{ + + expect(getAngleType(180)).toEqual("Straight angle"); + +}); // Case 5: Reflex angles +test (`should return "Reflex angle" when (180 < angle < 360)` ,() =>{ + + expect(getAngleType(190)).toEqual("Reflex angle"); + expect(getAngleType(300)).toEqual("Reflex angle"); + expect(getAngleType(200)).toEqual("Reflex angle"); +}); // Case 6: Invalid angles +test (`should return "Invalid angle" when (angle <= 0 or angle > 360)` ,() => { + + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(400)).toEqual("Invalid angle"); + expect(getAngleType(-10)).toEqual("Invalid angle"); +}); \ No newline at end of file From d4bdddd24beabc454a18dda2a88f60eea2490391 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sun, 15 Mar 2026 08:24:05 +0000 Subject: [PATCH 08/21] added special case fration 1,0 to the assert test cases. --- .../implement/2-is-proper-fraction.js | 2 ++ 1 file changed, 2 insertions(+) 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 b31b38b23e..6afeba8f72 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 @@ -45,3 +45,5 @@ assertEquals (isProperFraction(4, 4), false ); // negative numbers assertEquals (isProperFraction(-2, 4), true ); assertEquals (isProperFraction(5, -4), false ); +// special case +assertEquals(isProperFraction(1,0) , false); From 447f5f2cec91b43b084ce1d023c8b279f80262a2 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sun, 15 Mar 2026 08:40:10 +0000 Subject: [PATCH 09/21] added assert test for both negative numbers. --- .../implement/2-is-proper-fraction.js | 2 + .../2-is-proper-fraction.test.js | 41 +++++++++++++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) 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 6afeba8f72..432f4d7398 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 @@ -45,5 +45,7 @@ assertEquals (isProperFraction(4, 4), false ); // negative numbers assertEquals (isProperFraction(-2, 4), true ); assertEquals (isProperFraction(5, -4), false ); +assertEquals (isProperFraction (-3,-5), false); + // special case assertEquals(isProperFraction(1,0) , false); 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..a60b213d98 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 @@ -2,9 +2,42 @@ // We will use the same function, but write tests for it using Jest in this file. const isProperFraction = require("../implement/2-is-proper-fraction"); -// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories. - -// Special case: numerator is zero -test(`should return false when denominator is zero`, () => { +// denominator is zero +test("should return false when denominator is zero", () => { expect(isProperFraction(1, 0)).toEqual(false); }); + +// proper fraction (numerator < denominator) +test("should return true when numerator < denominator", () => { + expect(isProperFraction(1, 2)).toEqual(true); +}); + +// improper fraction (numerator > denominator) +test("should return false when numerator > denominator", () => { + expect(isProperFraction(5, 3)).toEqual(false); +}); + +// equal numbers +test("should return false when numerator === denominator", () => { + expect(isProperFraction(4, 4)).toEqual(false); +}); + +// numerator is zero +test("should return true when numerator is zero and denominator is positive", () => { + expect(isProperFraction(0, 5)).toEqual(true); +}); + +// negative numerator +test("should return false when numerator is negative", () => { + expect(isProperFraction(-2, 4)).toEqual(false); +}); + +// negative denominator +test("should return false when denominator is negative", () => { + expect(isProperFraction(5, -4)).toEqual(false); +}); + +// both negative +test("should return false when both numerator and denominator are negative", () => { + expect(isProperFraction(-3, -5)).toEqual(false); +}); \ No newline at end of file From b215ef8d75dd5b818056b3fbfb597d889121c00d Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sun, 15 Mar 2026 08:43:54 +0000 Subject: [PATCH 10/21] I wrote tests for the diffrent fraction cases using Jest in this file --- .../implement/2-is-proper-fraction.js | 3 +++ 1 file changed, 3 insertions(+) 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 432f4d7398..3679b17ded 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 @@ -49,3 +49,6 @@ assertEquals (isProperFraction (-3,-5), false); // special case assertEquals(isProperFraction(1,0) , false); + +assertEquals (isProperFraction (0,5), true); + From d4660145fc30efd3aa540fb2203d92517bb636a6 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sun, 15 Mar 2026 08:48:00 +0000 Subject: [PATCH 11/21] I Wrote tests in Jest syntax to cover all possible outcomes for the getCardValue function. --- .../3-get-card-value.test.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) 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..846c9816ca 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,32 @@ test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); + +// Case 2: Number Cards (2–10) +test("Should return the numeric value for number cards", () => { + expect(getCardValue("2♠")).toEqual(2); + expect(getCardValue("5♥")).toEqual(5); + expect(getCardValue("9♦")).toEqual(9); + expect(getCardValue("10♣")).toEqual(10); +}); + +// Case 3: Face Cards (J, Q, K) +test("Should return 10 for face cards", () => { + expect(getCardValue("J♠")).toEqual(10); + expect(getCardValue("Q♥")).toEqual(10); + expect(getCardValue("K♦")).toEqual(10); +}); + +// Case 4: Invalid Cards +test("Should throw an error for invalid cards", () => { + expect(() => getCardValue("1♠")).toThrowError(); + expect(() => getCardValue("B♣")).toThrowError(); + expect(() => getCardValue("10?")).toThrowError(); + expect(() => getCardValue("invalid")).toThrowError(); +}); + + + // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) // Face Cards (J, Q, K) From 17f285abda3c81a4bf06660aab85e4227c217eed Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sun, 15 Mar 2026 09:25:41 +0000 Subject: [PATCH 12/21] implemented the function countChar that counts the number of times a character occurs in a string --- Sprint-3/2-practice-tdd/count.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..be39e986a2 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,7 @@ -function countChar(stringOfCharacters, findCharacter) { - return 5 +function countChar(str, char) { + + return str.split(char).length -1; } +console.log(countChar('lol', 'a')); module.exports = countChar; From 665ebcab02fc3e5cdeded614685177ad37306b4b Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sun, 15 Mar 2026 23:32:54 +0000 Subject: [PATCH 13/21] I implimented a function to get ordinal number for different ordinal cases nd, th, st, and rd. --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 10 ++++++++-- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db13..8613add937 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,11 @@ -function getOrdinalNumber(num) { - return "1st"; +function getOrdinalNumber(n) { + if (n % 100 >= 11 && n % 100 <= 13) return n + "th"; + + if (n % 10 === 1) return n + "st"; + if (n % 10 === 2) return n + "nd"; + if (n % 10 === 3) return n + "rd"; + + return n + "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..4711f681db 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -18,3 +18,17 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(131)).toEqual("131st"); }); + +// Case 2 : Ordinal number ending with 2 +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(142).toEqual("142nd")); +}); +// Case 3: Ordinal numbers ending with 1 (but not 13) +test("should append 'rd' for numbers ending with 3, except those ending with 13" , ()=> { + expect(getOrdinalNumber(3).toEqual("2rd")); + expect(getOrdinalNumber(23).toEqual("23rd")); + expect(getOrdinalNumber(143).toEqual("143rd")); +}); + From ecc3f99a48b565cba5a17d61152247a74517db17 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sun, 15 Mar 2026 23:35:11 +0000 Subject: [PATCH 14/21] created extra test cass for the getOrdinalNumber fraction --- .../2-practice-tdd/get-ordinal-number.test.js | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) 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 4711f681db..9906023c57 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -13,22 +13,23 @@ const getOrdinalNumber = require("./get-ordinal-number"); // Case 1: Numbers ending with 1 (but not 11) // When the number ends with 1, except those ending with 11, // Then the function should return a string by appending "st" to the number. +// Case 1: numbers ending with 1 (except 11) 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"); }); -// Case 2 : Ordinal number ending with 2 -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(142).toEqual("142nd")); -}); -// Case 3: Ordinal numbers ending with 1 (but not 13) -test("should append 'rd' for numbers ending with 3, except those ending with 13" , ()=> { - expect(getOrdinalNumber(3).toEqual("2rd")); - expect(getOrdinalNumber(23).toEqual("23rd")); - expect(getOrdinalNumber(143).toEqual("143rd")); +// Case 2: numbers ending with 2 (except 12) +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(142)).toEqual("142nd"); }); +// Case 3: numbers ending with 3 (except 13) +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(143)).toEqual("143rd"); +}); \ No newline at end of file From f265055b078c7574faf6c4018d9e3d69d5598642 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Tue, 17 Mar 2026 12:26:17 +0000 Subject: [PATCH 15/21] I implemented a function for the ordinal number cases - Continue testing and implementing getOrdinalNumber for additional cases. - Write tests using Jest . --- Sprint-3/2-practice-tdd/repeat-str.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 3838c7b003..1353f6ba5e 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,4 +1,5 @@ function repeatStr() { + return "hellohellohello"; } From f012a521cbba3f902f3a7dc6788896edf21b1ecf Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Tue, 17 Mar 2026 12:30:33 +0000 Subject: [PATCH 16/21] I implemented repeatStr function. --- Sprint-3/2-practice-tdd/repeat-str.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 1353f6ba5e..aaa1d5975c 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,6 +1,6 @@ -function repeatStr() { - - return "hellohellohello"; +function repeatStr(str) { + + return str.repeat(3); } module.exports = repeatStr; From 5d0e89591874353521cb6587cedf72a46f99b391 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Tue, 17 Mar 2026 12:42:12 +0000 Subject: [PATCH 17/21] I wrote different test cases to handel repeating string for times more than 1, and to give empty out put for (0) and 'invalid count' output for negative counts. --- Sprint-3/2-practice-tdd/repeat-str.test.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index a3fc1196c4..f460445a23 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -20,13 +20,29 @@ 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 = "hello"; + const count = 1; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("hello"); +}); // 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 repeat the string count times", () => { + 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 repeat the string count times", () => { + const str = "hello"; + const count = -1; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("invalid count"); +}); \ No newline at end of file From 866a426fe7c66dfcb1acde1cc88540fc93b27381 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Tue, 17 Mar 2026 12:43:56 +0000 Subject: [PATCH 18/21] reedited the function. --- Sprint-3/2-practice-tdd/repeat-str.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index aaa1d5975c..96bda5eb42 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,6 +1,7 @@ -function repeatStr(str) { - - return str.repeat(3); +function repeatStr(str, count) { + if( count >= 0 ) + {return str.repeat (count)}; +else { return 'invalid count'}; } module.exports = repeatStr; From c8ef645c4e05eafbb48d725e5e05413e8bc834fd Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Tue, 17 Mar 2026 12:52:46 +0000 Subject: [PATCH 19/21] I removed the console.log (greetingStr) code because it is unreachable code. - deleted the const greetingStr = greeting + ", " + name + "!"; because it is a redundant code that repeated already int the return function. --- Sprint-3/3-dead-code/exercise-1.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js index 4d09f15fa9..22cbda0ff8 100644 --- a/Sprint-3/3-dead-code/exercise-1.js +++ b/Sprint-3/3-dead-code/exercise-1.js @@ -1,3 +1,4 @@ + // Find the instances of unreachable and redundant code - remove them! // The sayHello function should continue to work for any reasonable input it's given. @@ -5,9 +6,7 @@ let testName = "Jerry"; const greeting = "hello"; function sayHello(greeting, name) { - const greetingStr = greeting + ", " + name + "!"; return `${greeting}, ${name}!`; - console.log(greetingStr); } testName = "Aman"; From 2b00771709c74e2deea2152274907ef5e3d420be Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Tue, 17 Mar 2026 12:58:20 +0000 Subject: [PATCH 20/21] I removed the capitalisedPets variable as it unused code. aslo removed the logPets function as it doesn't called. --- Sprint-3/3-dead-code/exercise-2.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js index 56d7887c4c..eecc0d358b 100644 --- a/Sprint-3/3-dead-code/exercise-2.js +++ b/Sprint-3/3-dead-code/exercise-2.js @@ -2,12 +2,8 @@ // 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 petsStartingWithH = pets.filter((pet) => pet[0] === "h"); -function logPets(petsArr) { - petsArr.forEach((pet) => console.log(pet)); -} function countAndCapitalisePets(petsArr) { const petCount = {}; From eb47bc58d4a3427c63ee9adea89a26f503f12fb5 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Wed, 18 Mar 2026 08:43:16 +0000 Subject: [PATCH 21/21] I created a new branch for sprint 3 repo 1 implement and creat testes --- Sprint-3/4-stretch/password-validator.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-3/4-stretch/password-validator.js b/Sprint-3/4-stretch/password-validator.js index b55d527dba..e0ff13ef30 100644 --- a/Sprint-3/4-stretch/password-validator.js +++ b/Sprint-3/4-stretch/password-validator.js @@ -1,5 +1,8 @@ function passwordValidator(password) { - return password.length < 5 ? false : true + if (password.length< 8) + + {return 'Password must be at least 8 characters long'}; + }