From 9b98e48aa51d1fa41f84c42401d541cf869b8359 Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Wed, 18 Jun 2025 15:13:39 +0100 Subject: [PATCH 01/23] implemented & tested function for all angle types --- .../2-mandatory-rewrite/1-get-angle-type.js | 7 ++-- .../1-get-angle-type.test.js | 32 +++++++++++++++++-- .../2-is-proper-fraction.js | 7 ++-- .../2-is-proper-fraction.test.js | 15 +++++++++ .../2-mandatory-rewrite/3-get-card-value.js | 4 +-- .../3-get-card-value.test.js | 7 ++++ 6 files changed, 64 insertions(+), 8 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js index d61254bd7..ee887bd32 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js @@ -1,7 +1,10 @@ function getAngleType(angle) { if (angle === 90) return "Right angle"; - // replace with your completed function from key-implement - + if (angle < 90) return "Acute angle"; + if (angle > 90 && angle < 180) return "Obtuse angle"; + if (angle === 180) return "Straight angle"; + if (angle > 180 && angle < 360) return "Reflex angle"; + return "invalid"; } diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js index b62827b7c..ae48deb06 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js @@ -4,21 +4,49 @@ test("should identify right angle (90°)", () => { expect(getAngleType(90)).toEqual("Right angle"); }); -// REPLACE the comments with the tests -// make your test descriptions as clear and readable as possible +test("should identify Acute agles", () => { + expect(getAngleType(1)).toEqual("Acute angle"); + expect(getAngleType(88)).toEqual("Acute angle"); +}); + + // Case 2: Identify Acute Angles: // When the angle is less than 90 degrees, // Then the function should return "Acute angle" + +test("should identify Obtuse angle", () => { + expect(getAngleType(99)).toEqual("Obtuse angle"); + expect(getAngleType(179)).toEqual("Obtuse angle"); +}); + + // Case 3: Identify Obtuse Angles: // When the angle is greater than 90 degrees and less than 180 degrees, // Then the function should return "Obtuse angle" +test("should identify Straight angle", () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}); + + + // Case 4: Identify Straight Angles: // When the angle is exactly 180 degrees, // Then the function should return "Straight angle" +test("should identify Reflex angle", () => { + expect(getAngleType(181)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); +}); + // Case 5: Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, // Then the function should return "Reflex angle" + + +test("should identify angle over 360", () => { + expect(getAngleType(360)).toEqual("invalid"); + expect(getAngleType(370)).toEqual("invalid"); +}); \ No newline at end of file diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js index 9836fe398..3678cd07e 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js @@ -1,6 +1,9 @@ function isProperFraction(numerator, denominator) { - if (numerator < denominator) return true; - // add your completed function from key-implement here + if (numerator < denominator && (numerator/denominator) > 0) return true; + if (numerator > denominator) return false; + if (numerator < denominator && (numerator/denominator) < 0) return "Negative Fraction"; + if (numerator === denominator ) return "Not really a fraction"; + } module.exports = isProperFraction; \ No newline at end of file diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js index ff1cc8173..1e81328f5 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js @@ -6,6 +6,21 @@ test("should return true for a proper fraction", () => { // Case 2: Identify Improper Fractions: +test("should return true for an improper fraction", () => { + expect(isProperFraction(11, 3)).toEqual(false); + expect(isProperFraction(7, 2)).toEqual(false); +}); + + // Case 3: Identify Negative Fractions: +test("should return a negative fraction", () => { + expect(isProperFraction(-11, 3)).toEqual("Negative Fraction"); +}); + + // Case 4: Identify Equal Numerator and Denominator: + +test("should return a whole number", () => { + expect(isProperFraction(4, 4)).toEqual("Not really a fraction"); +}); \ No newline at end of file diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js index 0d95d3736..3cbed4880 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js @@ -1,5 +1,5 @@ function getCardValue(card) { - // replace with your code from key-implement - return 11; + if (card === "Ace of Spades") return 11; + if (card === "Numerical card") return 2-10; } module.exports = getCardValue; \ No newline at end of file diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js index 03a8e2f34..9107c47b0 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js @@ -6,6 +6,13 @@ test("should return 11 for Ace of Spades", () => { }); // Case 2: Handle Number Cards (2-10): + +test("should return Numerical card for cards (2-10)", () => { + + expect(6).toEqual("Numerical card"); +}); + + // Case 3: Handle Face Cards (J, Q, K): // Case 4: Handle Ace (A): // Case 5: Handle Invalid Cards: From 1e656559082244d1f5ef5ee92e25c0a46dbc7b6e Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Wed, 18 Jun 2025 16:19:45 +0100 Subject: [PATCH 02/23] tested & implemented different card types --- .../2-mandatory-rewrite/3-get-card-value.js | 5 ++++- .../3-get-card-value.test.js | 21 +++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js index 3cbed4880..7fe8bc1bc 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js @@ -1,5 +1,8 @@ function getCardValue(card) { if (card === "Ace of Spades") return 11; - if (card === "Numerical card") return 2-10; + if (card === "Number Cards") return "2-10"; + if (card === "Ace") return "A"; + if (card === "Face Cards") return "J, Q, K"; + } module.exports = getCardValue; \ No newline at end of file diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js index 9107c47b0..015a59482 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js @@ -1,18 +1,27 @@ const getCardValue = require("./3-get-card-value"); test("should return 11 for Ace of Spades", () => { - const aceofSpades = getCardValue("A♠"); + const aceofSpades = getCardValue("Ace of Spades"); expect(aceofSpades).toEqual(11); - }); +}); // Case 2: Handle Number Cards (2-10): - -test("should return Numerical card for cards (2-10)", () => { - - expect(6).toEqual("Numerical card"); +test("should return 2-10 for Number Cards", () => { + const numberCards = getCardValue("Number Cards"); + expect(numberCards).toEqual("2-10"); }); // Case 3: Handle Face Cards (J, Q, K): +test("should return J, Q, K for Face Cards", () => { + const faceCards = getCardValue("Face Cards"); + expect(faceCards).toEqual("J, Q, K"); +}); + // Case 4: Handle Ace (A): +test("should return A for Ace", () => { + const ace = getCardValue("Ace"); + expect(ace).toEqual("A"); +}); + // Case 5: Handle Invalid Cards: From 5634292d229b5e059a9fa3f33fcba80588607689 Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Thu, 19 Jun 2025 15:31:46 +0100 Subject: [PATCH 03/23] implemented and tested the char count --- .../3-mandatory-practice/implement/count.js | 9 ++++-- .../implement/count.test.js | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/count.js b/Sprint-3/3-mandatory-practice/implement/count.js index fce249650..c4ea04b96 100644 --- a/Sprint-3/3-mandatory-practice/implement/count.js +++ b/Sprint-3/3-mandatory-practice/implement/count.js @@ -1,5 +1,10 @@ -function countChar(stringOfCharacters, findCharacter) { - return 5 +function countChar(str, char) { + if (str.includes(char) === true) { + return str.split(char).length -1; + } else { + return 0; + } + } module.exports = countChar; \ No newline at end of file diff --git a/Sprint-3/3-mandatory-practice/implement/count.test.js b/Sprint-3/3-mandatory-practice/implement/count.test.js index 42baf4b4b..008c28bb2 100644 --- a/Sprint-3/3-mandatory-practice/implement/count.test.js +++ b/Sprint-3/3-mandatory-practice/implement/count.test.js @@ -17,8 +17,38 @@ test("should count multiple occurrences of a character", () => { expect(count).toEqual(5); }); +test("should count multiple occurrences of a character", () => { + const str = "bandana"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(3); +}); + +test("should count multiple occurrences of a character", () => { + const str = "mississippi"; + const char = "i"; + const count = countChar(str, char); + expect(count).toEqual(4); + +}); + // Scenario: No Occurrences // Given the input string str, // And a character char that does not exist within the case-sensitive str, // When the function is called with these inputs, // Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str. + +test("should return 0 in a case-sensitive str", () => { + const str = "HHHHHH"; + const char = "h"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); + +test("should return 0 in a case-sensitive str", () => { + const str = "bubble"; + const char = "B"; + const count = countChar(str, char); + expect(count).toEqual(0); + +}); \ No newline at end of file From 5d17a566238ff9a85506385e7df3df61765d755f Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Thu, 19 Jun 2025 19:40:50 +0100 Subject: [PATCH 04/23] implemented and tested ordinal number function --- .../implement/get-ordinal-number.js | 12 +++++++++++- .../implement/get-ordinal-number.test.js | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js index 24f528b0d..9c4ccb72f 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js @@ -1,5 +1,15 @@ function getOrdinalNumber(num) { - return "1st"; + if (num === 1) { + return "1st"; + } else if(num === 21) { + return "21st"; + } else if(num === 2) { + return "2nd"; + } else if(num === 22) { + return "22nd"; + } else { + return `${num}th`; + } } module.exports = getOrdinalNumber; \ No newline at end of file diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js index 6d55dfbb4..7b7a1b621 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js @@ -11,3 +11,17 @@ const getOrdinalNumber = require("./get-ordinal-number"); test("should return '1st' for 1", () => { expect(getOrdinalNumber(1)).toEqual("1st"); }); + + +test("should return '21st' for 21", () => { + expect(getOrdinalNumber(21)).toEqual("21st"); +}); + +test("should get '2nd' for 2", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); +}); + + +test("should get '22nd' for 22", () => { + expect(getOrdinalNumber(22)).toEqual("22nd"); +}); \ No newline at end of file From 531b3edea05e49a5ad8c36dfa4dc233c76c14d49 Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Thu, 19 Jun 2025 20:27:38 +0100 Subject: [PATCH 05/23] implemented and tested the repeat function --- .../3-mandatory-practice/implement/repeat.js | 10 +++++++-- .../implement/repeat.test.js | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.js b/Sprint-3/3-mandatory-practice/implement/repeat.js index 621f9bd35..0d49a54c1 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.js @@ -1,5 +1,11 @@ -function repeat() { - return "hellohellohello"; +function repeat(str, count) { + if(count > 0) { + return str.repeat(count); + } else if (count === 0) { + return " "; + } else { + throw new Error("Invalid number. Please enter a positive number or 0 for count"); + } } module.exports = repeat; \ No newline at end of file diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.test.js b/Sprint-3/3-mandatory-practice/implement/repeat.test.js index 8a4ab42ef..a0a60966d 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.test.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.test.js @@ -21,12 +21,33 @@ test("should repeat the string count times", () => { // When the repeat function is called with these inputs, // Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition. +test("should return the original string without repetition", () => { + const str = "hi"; + const count = 1; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual("hi"); + }); + // case: Handle Count of 0: // Given a target string str and a count equal to 0, // When the repeat function is called with these inputs, // Then it should return an empty string, ensuring that a count of 0 results in an empty output. +test("should return an empty string for count = 0", () => { + const str = "Good Morning"; + const count = 0; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual(" "); + }); + + // case: Negative Count: // Given a target string str and a negative integer count, // When the repeat function is called with these inputs, // Then it should throw an error or return an appropriate error message, as negative counts are not valid. + +test("should throw an error / return an error message", () => { + const str = "Bye"; + const count = -3; + expect(() => repeat(str, count)).toThrow("Invalid number. Please enter a positive number or 0 for count"); + }); From 1472a6e2023ca5d57996f40f37157229499c435e Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Sat, 28 Jun 2025 14:18:00 +0100 Subject: [PATCH 06/23] changed to make angles <=0 evaluates to "invalid" --- Sprint-3/2-mandatory-rewrite/1-get-angle-type.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js index ee887bd32..31359dc48 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js @@ -1,6 +1,6 @@ function getAngleType(angle) { if (angle === 90) return "Right angle"; - if (angle < 90) return "Acute angle"; + if (0 < angle && angle < 90) return "Acute angle"; if (angle > 90 && angle < 180) return "Obtuse angle"; if (angle === 180) return "Straight angle"; if (angle > 180 && angle < 360) return "Reflex angle"; From 0286d78e47e7393db5f6c7a19707e2fd5a644b82 Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Sat, 28 Jun 2025 14:25:13 +0100 Subject: [PATCH 07/23] updated the last test description for more clarity. --- Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js index ae48deb06..cace6eb38 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js @@ -46,7 +46,7 @@ test("should identify Reflex angle", () => { // Then the function should return "Reflex angle" -test("should identify angle over 360", () => { +test("should identify angle not in range (0, 360)", () => { expect(getAngleType(360)).toEqual("invalid"); expect(getAngleType(370)).toEqual("invalid"); }); \ No newline at end of file From 5bd333efe49e94ed708339eaafdefe00cacd1ce9 Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Sat, 28 Jun 2025 14:38:08 +0100 Subject: [PATCH 08/23] simplified the conditions of my function --- Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js index 3678cd07e..95c5dbc81 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js @@ -1,9 +1,9 @@ function isProperFraction(numerator, denominator) { - if (numerator < denominator && (numerator/denominator) > 0) return true; - if (numerator > denominator) return false; - if (numerator < denominator && (numerator/denominator) < 0) return "Negative Fraction"; - if (numerator === denominator ) return "Not really a fraction"; - + if (numerator < denominator) { + return true; + } else { + return false; + } } module.exports = isProperFraction; \ No newline at end of file From 3498122248b477b8da09c17c18baf718315f9425 Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Sat, 28 Jun 2025 15:10:08 +0100 Subject: [PATCH 09/23] updated function implementation & tests --- Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js | 9 +++++---- .../2-mandatory-rewrite/2-is-proper-fraction.test.js | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js index 95c5dbc81..bf4335691 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js @@ -1,9 +1,10 @@ function isProperFraction(numerator, denominator) { - if (numerator < denominator) { - return true; - } else { + if (numerator >= denominator) { return false; - } + } else { + return true; + + } } module.exports = isProperFraction; \ No newline at end of file diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js index 1e81328f5..a5f645ce5 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js @@ -6,7 +6,7 @@ test("should return true for a proper fraction", () => { // Case 2: Identify Improper Fractions: -test("should return true for an improper fraction", () => { +test("should return false for an improper fraction", () => { expect(isProperFraction(11, 3)).toEqual(false); expect(isProperFraction(7, 2)).toEqual(false); }); @@ -15,12 +15,13 @@ test("should return true for an improper fraction", () => { // Case 3: Identify Negative Fractions: test("should return a negative fraction", () => { - expect(isProperFraction(-11, 3)).toEqual("Negative Fraction"); + expect(isProperFraction(-2, 3)).toEqual(true); + expect(isProperFraction(18, -7)).toEqual(false); }); // Case 4: Identify Equal Numerator and Denominator: test("should return a whole number", () => { - expect(isProperFraction(4, 4)).toEqual("Not really a fraction"); + expect(isProperFraction(4, 4)).toEqual(false); }); \ No newline at end of file From 33809e89fdb0b25e56bc7e278d878c9a364a3dc6 Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Sat, 28 Jun 2025 16:21:04 +0100 Subject: [PATCH 10/23] updated card function implementation & test --- .../2-mandatory-rewrite/3-get-card-value.js | 44 ++++++++++++++++--- .../3-get-card-value.test.js | 42 +++++++++++++----- 2 files changed, 71 insertions(+), 15 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js index 7fe8bc1bc..b8325982a 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js @@ -1,8 +1,42 @@ function getCardValue(card) { - if (card === "Ace of Spades") return 11; - if (card === "Number Cards") return "2-10"; - if (card === "Ace") return "A"; - if (card === "Face Cards") return "J, Q, K"; - + switch(card) { + case "A♠": + case "A": + return 11; + break; + case "2♠": + return 2; + break; + case "3♠": + return 3; + break; + case "4♠": + return 4; + break; + case "5♠": + return 5; + break; + case "6♠": + return 6; + break; + case "7♠": + return 7; + break; + case "8♠": + return 8; + break; + case "9♠": + return 9; + break; + case "10♠": + case "J♠": + case "K♠": + case "Q♠": + return 10; + break; + default: + throw new Error("Invalid card rank"); + + } } module.exports = getCardValue; \ No newline at end of file diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js index 015a59482..8c71dfd92 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js @@ -1,27 +1,49 @@ const getCardValue = require("./3-get-card-value"); test("should return 11 for Ace of Spades", () => { - const aceofSpades = getCardValue("Ace of Spades"); + const aceofSpades = getCardValue("A♠"); expect(aceofSpades).toEqual(11); }); // Case 2: Handle Number Cards (2-10): -test("should return 2-10 for Number Cards", () => { - const numberCards = getCardValue("Number Cards"); - expect(numberCards).toEqual("2-10"); +test("should return 3 for 3♠ card", () => { + const numberCards = getCardValue("3♠"); + expect(numberCards).toEqual(3); }); +test("should return 9 for 9♠", () => { + const numberCards = getCardValue("9♠"); + expect(numberCards).toEqual(9); +}); + + // Case 3: Handle Face Cards (J, Q, K): -test("should return J, Q, K for Face Cards", () => { - const faceCards = getCardValue("Face Cards"); - expect(faceCards).toEqual("J, Q, K"); +test("should return 10 for K♠ card", () => { + const faceCards = getCardValue("K♠"); + expect(faceCards).toEqual(10); +}); + +test("should return 10 for Q♠ card", () => { + const faceCards = getCardValue("Q♠"); + expect(faceCards).toEqual(10); }); // Case 4: Handle Ace (A): -test("should return A for Ace", () => { - const ace = getCardValue("Ace"); - expect(ace).toEqual("A"); +test("should return 11 for Ace", () => { + const ace = getCardValue("A"); + expect(ace).toEqual(11); }); // Case 5: Handle Invalid Cards: +test("should throw Invalid card rank for invalid cards", () => { + + let card = "Z♠" + expect(() => getCardValue(card)).toThrow("Invalid card rank"); +}); + +test("should throw Invalid card rank for invalid cards", () => { + + let card = "11♠" + expect(() => getCardValue(card)).toThrow("Invalid card rank"); +}); From f8895ad0d2493bd24e917f4dcefe2ee064f1c0ca Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Sun, 29 Jun 2025 22:45:13 +0100 Subject: [PATCH 11/23] changed ordinal number function to widen range --- .../implement/get-ordinal-number.js | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js index 9c4ccb72f..da0e93c96 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js @@ -1,15 +1,25 @@ function getOrdinalNumber(num) { - if (num === 1) { - return "1st"; - } else if(num === 21) { - return "21st"; - } else if(num === 2) { - return "2nd"; - } else if(num === 22) { - return "22nd"; - } else { + const lastDigit = num % 10; + const lastTwoDigits = num % 100; + if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { return `${num}th`; - } + } + + switch(lastDigit) { + case 1: + return `${num}st`; + break; + case 2: + return `${num}nd`; + break; + case 3: + return `${num}rd`; + break; + default: + return `${num}th`; + } + + } module.exports = getOrdinalNumber; \ No newline at end of file From 06411c8f3dc391244a3818ad428acfae4923a7ce Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Sun, 29 Jun 2025 23:50:36 +0100 Subject: [PATCH 12/23] corrected my empty string return --- Sprint-3/3-mandatory-practice/implement/repeat.js | 2 +- Sprint-3/3-mandatory-practice/implement/repeat.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.js b/Sprint-3/3-mandatory-practice/implement/repeat.js index 0d49a54c1..e644b92f0 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.js @@ -2,7 +2,7 @@ function repeat(str, count) { if(count > 0) { return str.repeat(count); } else if (count === 0) { - return " "; + return ""; } else { throw new Error("Invalid number. Please enter a positive number or 0 for count"); } diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.test.js b/Sprint-3/3-mandatory-practice/implement/repeat.test.js index a0a60966d..5ee534308 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.test.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.test.js @@ -37,7 +37,7 @@ test("should return an empty string for count = 0", () => { const str = "Good Morning"; const count = 0; const repeatedStr = repeat(str, count); - expect(repeatedStr).toEqual(" "); + expect(repeatedStr).toEqual(""); }); From 489b22f441b2fdef96600371e40bd0e3bd1ec862 Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Mon, 30 Jun 2025 00:01:10 +0100 Subject: [PATCH 13/23] simplified my function --- Sprint-3/3-mandatory-practice/implement/count.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/count.js b/Sprint-3/3-mandatory-practice/implement/count.js index c4ea04b96..cd28855c0 100644 --- a/Sprint-3/3-mandatory-practice/implement/count.js +++ b/Sprint-3/3-mandatory-practice/implement/count.js @@ -1,10 +1,5 @@ function countChar(str, char) { - if (str.includes(char) === true) { return str.split(char).length -1; - } else { - return 0; - } - } module.exports = countChar; \ No newline at end of file From 6284562edc72a31a6a86ec08b26200ef1d4ea25b Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Mon, 30 Jun 2025 19:32:00 +0100 Subject: [PATCH 14/23] added Math.abs() --- Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js index bf4335691..fc6fa7677 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js @@ -1,9 +1,8 @@ function isProperFraction(numerator, denominator) { - if (numerator >= denominator) { + if (Math.abs(numerator/denominator) >= 1) { return false; } else { return true; - } } From c4a2aca00c5c57f4df5aff0c38d59c30384d4c43 Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Mon, 30 Jun 2025 23:42:43 +0100 Subject: [PATCH 15/23] edited function to cover different suits & ranks --- .../2-mandatory-rewrite/3-get-card-value.js | 46 +++++++------------ 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js index b8325982a..3936f908b 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js @@ -1,37 +1,23 @@ function getCardValue(card) { - switch(card) { - case "A♠": + const rank = card.slice(0, 1) + switch(rank) { case "A": return 11; break; - case "2♠": - return 2; - break; - case "3♠": - return 3; - break; - case "4♠": - return 4; - break; - case "5♠": - return 5; - break; - case "6♠": - return 6; - break; - case "7♠": - return 7; - break; - case "8♠": - return 8; - break; - case "9♠": - return 9; - break; - case "10♠": - case "J♠": - case "K♠": - case "Q♠": + case "2": + case "3": + case "4": + case "5": + case "6": + case "7": + case "8": + case "9": + case "10": + return Number(rank); + break; + case "J": + case "K": + case "Q": return 10; break; default: From 7c4389d5009a2c95157bee43a68c3b5e27a5f626 Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Mon, 30 Jun 2025 23:49:02 +0100 Subject: [PATCH 16/23] updated tests descriptions --- Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js index 8c71dfd92..fc8ab69c7 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js @@ -6,7 +6,7 @@ test("should return 11 for Ace of Spades", () => { }); // Case 2: Handle Number Cards (2-10): -test("should return 3 for 3♠ card", () => { +test("should return 2-10 for cards rank (2-10)", () => { const numberCards = getCardValue("3♠"); expect(numberCards).toEqual(3); }); @@ -19,12 +19,12 @@ test("should return 9 for 9♠", () => { // Case 3: Handle Face Cards (J, Q, K): -test("should return 10 for K♠ card", () => { - const faceCards = getCardValue("K♠"); +test("should return 10 for face cards (J, Q, K)", () => { + const faceCards = getCardValue("K♣︎"); expect(faceCards).toEqual(10); }); -test("should return 10 for Q♠ card", () => { +test("should return 10 for face cards (J, Q, K)", () => { const faceCards = getCardValue("Q♠"); expect(faceCards).toEqual(10); }); From 499bcf101d24599944d6f37665b82d53e5c96310 Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Tue, 1 Jul 2025 00:38:16 +0100 Subject: [PATCH 17/23] updated tests descriptions --- .../implement/get-ordinal-number.test.js | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js index 7b7a1b621..e6efc58d9 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js @@ -8,20 +8,28 @@ const getOrdinalNumber = require("./get-ordinal-number"); // When the number is 1, // Then the function should return "1st" -test("should return '1st' for 1", () => { +test("should append 'st' to numbers ending with 1 and not ending with 11", () => { expect(getOrdinalNumber(1)).toEqual("1st"); }); +test("should append 'st' to numbers ending with 1 and not ending with 11", () => { + expect(getOrdinalNumber(41)).toEqual("41st"); + }); + -test("should return '21st' for 21", () => { - expect(getOrdinalNumber(21)).toEqual("21st"); +test("should append 'nd' to numbers ending with 2", () => { + expect(getOrdinalNumber(62)).toEqual("61nd"); }); -test("should get '2nd' for 2", () => { - expect(getOrdinalNumber(2)).toEqual("2nd"); +test("should append 'rd' to numbers ending with 3", () => { + expect(getOrdinalNumber(93)).toEqual("93nd"); }); -test("should get '22nd' for 22", () => { - expect(getOrdinalNumber(22)).toEqual("22nd"); +test("should append 'th' to numbers ending (4-9)", () => { + expect(getOrdinalNumber(8)).toEqual("8th"); +}); + +test("should append 'th' to numbers ending (11-13)", () => { + expect(getOrdinalNumber(12)).toEqual("12th"); }); \ No newline at end of file From 34dd33f3c76a5008c654ef7c000099abbb31f5d3 Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Tue, 1 Jul 2025 00:44:57 +0100 Subject: [PATCH 18/23] updated the error message --- Sprint-3/3-mandatory-practice/implement/repeat.js | 7 +++++-- Sprint-3/3-mandatory-practice/implement/repeat.test.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.js b/Sprint-3/3-mandatory-practice/implement/repeat.js index e644b92f0..ba4263340 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.js @@ -4,8 +4,11 @@ function repeat(str, count) { } else if (count === 0) { return ""; } else { - throw new Error("Invalid number. Please enter a positive number or 0 for count"); + throw new Error("Invalid number"); } } -module.exports = repeat; \ No newline at end of file +module.exports = repeat; + + +console.log(repeat("abc", -1)) \ No newline at end of file diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.test.js b/Sprint-3/3-mandatory-practice/implement/repeat.test.js index 5ee534308..aec3780bf 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.test.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.test.js @@ -49,5 +49,5 @@ test("should return an empty string for count = 0", () => { test("should throw an error / return an error message", () => { const str = "Bye"; const count = -3; - expect(() => repeat(str, count)).toThrow("Invalid number. Please enter a positive number or 0 for count"); + expect(() => repeat(str, count)).toThrow("Invalid number"); }); From 784a678e895fd7075725a2da3cca846dd406acff Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Tue, 1 Jul 2025 14:18:12 +0100 Subject: [PATCH 19/23] refactored Face Cards(J,Q,K) test further --- Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js index fc8ab69c7..dd0da636c 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js @@ -20,14 +20,12 @@ test("should return 9 for 9♠", () => { // Case 3: Handle Face Cards (J, Q, K): test("should return 10 for face cards (J, Q, K)", () => { - const faceCards = getCardValue("K♣︎"); - expect(faceCards).toEqual(10); + expect(getCardValue("J♣︎")).toEqual(10); + expect(getCardValue("Q♠")).toEqual(10); + expect(getCardValue("K♣︎")).toEqual(10); }); -test("should return 10 for face cards (J, Q, K)", () => { - const faceCards = getCardValue("Q♠"); - expect(faceCards).toEqual(10); -}); + // Case 4: Handle Ace (A): test("should return 11 for Ace", () => { From 0ec98ea8c7a4c47d603cda180a573c9f9be4ef5c Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Tue, 1 Jul 2025 14:20:04 +0100 Subject: [PATCH 20/23] refactored tests for (2-10) cards further --- Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js index dd0da636c..05344e87b 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js @@ -7,14 +7,11 @@ test("should return 11 for Ace of Spades", () => { // Case 2: Handle Number Cards (2-10): test("should return 2-10 for cards rank (2-10)", () => { - const numberCards = getCardValue("3♠"); - expect(numberCards).toEqual(3); + expect(getCardValue("2♠")).toEqual(2); + expect(getCardValue("9♣︎")).toEqual(9); + expect(getCardValue("7♠")).toEqual(7); }); -test("should return 9 for 9♠", () => { - const numberCards = getCardValue("9♠"); - expect(numberCards).toEqual(9); -}); From f7bfacf401f66e586724734147734ecec41d90a7 Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Tue, 1 Jul 2025 14:26:46 +0100 Subject: [PATCH 21/23] corrected mistakes in a few of ordinal num tests --- .../3-mandatory-practice/implement/get-ordinal-number.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js index e6efc58d9..ff222a413 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js @@ -18,11 +18,11 @@ test("should append 'st' to numbers ending with 1 and not ending with 11", () => test("should append 'nd' to numbers ending with 2", () => { - expect(getOrdinalNumber(62)).toEqual("61nd"); + expect(getOrdinalNumber(62)).toEqual("62nd"); }); test("should append 'rd' to numbers ending with 3", () => { - expect(getOrdinalNumber(93)).toEqual("93nd"); + expect(getOrdinalNumber(93)).toEqual("93rd"); }); From 8461178c7b8b7805fad389b975d0f42c3e12133f Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Tue, 1 Jul 2025 14:42:33 +0100 Subject: [PATCH 22/23] removed a bug from ordinal number'd function --- .../3-mandatory-practice/implement/get-ordinal-number.test.js | 4 +--- Sprint-3/3-mandatory-practice/implement/repeat.js | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js index ff222a413..3289f9c77 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js @@ -10,13 +10,11 @@ const getOrdinalNumber = require("./get-ordinal-number"); test("should append 'st' to numbers ending with 1 and not ending with 11", () => { expect(getOrdinalNumber(1)).toEqual("1st"); - }); - -test("should append 'st' to numbers ending with 1 and not ending with 11", () => { expect(getOrdinalNumber(41)).toEqual("41st"); }); + test("should append 'nd' to numbers ending with 2", () => { expect(getOrdinalNumber(62)).toEqual("62nd"); }); diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.js b/Sprint-3/3-mandatory-practice/implement/repeat.js index ba4263340..0fad7bc96 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.js @@ -11,4 +11,3 @@ function repeat(str, count) { module.exports = repeat; -console.log(repeat("abc", -1)) \ No newline at end of file From 16a010cd3b9a6648ace6b274ff9df63cce354c6d Mon Sep 17 00:00:00 2001 From: HassanOHOsman Date: Tue, 1 Jul 2025 14:50:38 +0100 Subject: [PATCH 23/23] further refactored ordinal numbers tests --- .../implement/get-ordinal-number.test.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js index 3289f9c77..f59c1606b 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js @@ -17,17 +17,22 @@ test("should append 'st' to numbers ending with 1 and not ending with 11", () => test("should append 'nd' to numbers ending with 2", () => { expect(getOrdinalNumber(62)).toEqual("62nd"); + expect(getOrdinalNumber(22)).toEqual("22nd"); }); test("should append 'rd' to numbers ending with 3", () => { expect(getOrdinalNumber(93)).toEqual("93rd"); + expect(getOrdinalNumber(3)).toEqual("3rd"); }); test("should append 'th' to numbers ending (4-9)", () => { - expect(getOrdinalNumber(8)).toEqual("8th"); + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(6)).toEqual("6th"); + expect(getOrdinalNumber(9)).toEqual("9th"); }); test("should append 'th' to numbers ending (11-13)", () => { expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); }); \ No newline at end of file