From dd85a1dc89466c4579c41d8d7f541503531a908b Mon Sep 17 00:00:00 2001 From: KayanatSuleman Date: Sat, 7 Feb 2026 11:39:56 +0000 Subject: [PATCH 01/13] checking to see the output of count using terminal --- Sprint-1/1-key-exercises/1-count.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..bf16e5b22 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -2,5 +2,6 @@ let count = 0; count = count + 1; +console.log(count); // Line 1 is a variable declaration, creating the count variable with an initial value of 0 -// Describe what line 3 is doing, in particular focus on what = is doing +// Describe what line 3 is doing, in particular focus on what = is doing \ No newline at end of file From c7ddaed669e179af83505419fa2b554e9704b8ae Mon Sep 17 00:00:00 2001 From: KayanatSuleman Date: Sat, 7 Feb 2026 12:01:45 +0000 Subject: [PATCH 02/13] Updating the script with comments detailing my understanding of the script --- Sprint-1/1-key-exercises/1-count.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index bf16e5b22..e1ca0860c 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,4 +4,8 @@ count = count + 1; console.log(count); // Line 1 is a variable declaration, creating the count variable with an initial value of 0 -// Describe what line 3 is doing, in particular focus on what = is doing \ No newline at end of file +// Describe what line 3 is doing, in particular focus on what = is doing +// The '=' assignment operator. It assigns the value on the right hand side to the variable on the left. +// The variable 'count' is initially assigned the value of 0. +// And the result is assigned back to count. +// This mean 'count; is updated each time this line runs. \ No newline at end of file From 035ca526ebf22ef2b177cbd6084e76dbf1d601d6 Mon Sep 17 00:00:00 2001 From: KayanatSuleman Date: Fri, 20 Feb 2026 21:12:12 +0000 Subject: [PATCH 03/13] Adding a jest test for 0 or empty string --- Sprint-3/2-practice-tdd/count.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf..8c3ac39ba 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -17,6 +17,13 @@ test("should count multiple occurrences of a character", () => { expect(count).toEqual(5); }); +test("should return 0 when character does not occur in string", () => { + const str = "hello"; + const char = "z"; + const count = countChar(str, char); + expect(count).toEqual(0); +}) + // Scenario: No Occurrences // Given the input string `str`, // And a character `char` that does not exist within `str`. From ea81dae3485cc548190c02f2ef6c99ff4b4fc435 Mon Sep 17 00:00:00 2001 From: KayanatSuleman Date: Fri, 20 Feb 2026 21:52:00 +0000 Subject: [PATCH 04/13] ensuring the test case is passing --- Sprint-3/2-practice-tdd/count.js | 9 ++++++++- Sprint-3/2-practice-tdd/count.test.js | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d..646e04ac0 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 count = 0; + + for (let x = 0; x < stringOfCharacters.length; x++) { + if (stringOfCharacters[x] === findCharacter) { + count ++; + } + } + return count; } module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 8c3ac39ba..3b2d03b55 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -22,7 +22,7 @@ test("should return 0 when character does not occur in string", () => { const char = "z"; const count = countChar(str, char); expect(count).toEqual(0); -}) +}); // Scenario: No Occurrences // Given the input string `str`, From 4377262c53c76737651ac811477d7949111af340 Mon Sep 17 00:00:00 2001 From: KayanatSuleman Date: Fri, 20 Feb 2026 22:37:23 +0000 Subject: [PATCH 05/13] Adding jest test for numbers ending in 2 --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 9 ++++++++- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 8 ++++++++ 2 files changed, 16 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 f95d71db1..c83ad9f61 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,12 @@ function getOrdinalNumber(num) { - return "1st"; + const lastDigit = num % 10; + const lastTwoDigits = num % 100; + + if (lastDigit === 1 && lastTwoDigits !== 11) return num + "st"; + if (lastDigit === 2 && lastTwoDigits !== 12) return num + "nd"; + if (lastDigit === 3 && lastTwoDigits !== 13) return num + "rd"; + + 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 adfa58560..e5e45f2f1 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -13,8 +13,16 @@ 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 in 1. 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: Numbers ending in 2 (but not 12). +test("appends 'nd' for numbers ending in 2 except 12", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(22)).toEqual("22nd"); +}); \ No newline at end of file From 3a89cc4a7348f9f61c34157005df42979744c01e Mon Sep 17 00:00:00 2001 From: KayanatSuleman Date: Fri, 20 Feb 2026 22:43:29 +0000 Subject: [PATCH 06/13] Adding jest test case for numbers ending in three --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 6 ++++++ 1 file changed, 6 insertions(+) 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 e5e45f2f1..e715a26c8 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -25,4 +25,10 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" test("appends 'nd' for numbers ending in 2 except 12", () => { expect(getOrdinalNumber(2)).toEqual("2nd"); expect(getOrdinalNumber(22)).toEqual("22nd"); +}); + +// Case 3: Numbers ending in 3. +test("appends 'rd' for numbers ending in 3 except 13", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(23)).toEqual("23rd"); }); \ No newline at end of file From 8b055ae820aa0e08d632930f2226c0885cf91275 Mon Sep 17 00:00:00 2001 From: KayanatSuleman Date: Fri, 20 Feb 2026 22:47:58 +0000 Subject: [PATCH 07/13] Adding jest cases for numbers ending in 4-9, and 0 --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 8 ++++++++ 1 file changed, 8 insertions(+) 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 e715a26c8..df331235e 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -31,4 +31,12 @@ test("appends 'nd' for numbers ending in 2 except 12", () => { test("appends 'rd' for numbers ending in 3 except 13", () => { expect(getOrdinalNumber(3)).toEqual("3rd"); expect(getOrdinalNumber(23)).toEqual("23rd"); +}); + +// Case 4: Numbers ending with 4-9, 0 (always ending "th") +test("should append 'th' for numbers ending with 0 or 4-9", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(20)).toEqual("20th"); + expect(getOrdinalNumber(49)).toEqual("49th"); }); \ No newline at end of file From c87f2abe3dde304dd0381a4184c735d320bef27a Mon Sep 17 00:00:00 2001 From: KayanatSuleman Date: Fri, 20 Feb 2026 22:49:11 +0000 Subject: [PATCH 08/13] Adding jest test case for special cases --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 df331235e..a47a9778d 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -39,4 +39,11 @@ test("should append 'th' for numbers ending with 0 or 4-9", () => { expect(getOrdinalNumber(10)).toEqual("10th"); expect(getOrdinalNumber(20)).toEqual("20th"); expect(getOrdinalNumber(49)).toEqual("49th"); -}); \ No newline at end of file +}); + +// Case 5: Special cases 11, 12, 13, 14, (always "th") +test("should append 'th' for numbers ending with 11, 12, or 13", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); +}); From 64d94f87f614fe75b61d3d3a332d0793051ceff6 Mon Sep 17 00:00:00 2001 From: KayanatSuleman Date: Fri, 20 Feb 2026 22:53:00 +0000 Subject: [PATCH 09/13] Adding a few other instances to cover the requirements correctly for test case5 --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 2 ++ 1 file changed, 2 insertions(+) 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 a47a9778d..75d3147ea 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -44,6 +44,8 @@ test("should append 'th' for numbers ending with 0 or 4-9", () => { // Case 5: Special cases 11, 12, 13, 14, (always "th") test("should append 'th' for numbers ending with 11, 12, or 13", () => { expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(13)).toEqual("13th"); expect(getOrdinalNumber(12)).toEqual("12th"); expect(getOrdinalNumber(13)).toEqual("13th"); + expect(getOrdinalNumber(14)).toEqual("14th"); }); From 6916541744238c3be4cadf7b04e6f72be37a99cb Mon Sep 17 00:00:00 2001 From: KayanatSuleman Date: Fri, 20 Feb 2026 22:57:05 +0000 Subject: [PATCH 10/13] Adding jest test case for case: handle count of 1 --- Sprint-3/2-practice-tdd/repeat-str.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index a3fc1196c..5dbec6b20 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -20,7 +20,9 @@ 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 return the original string when count is 1", () => { + expect(repeatStr("hello", 1)).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, From ac6fa53fe67c5381dd2d92f65352a3c64ac5f811 Mon Sep 17 00:00:00 2001 From: KayanatSuleman Date: Fri, 20 Feb 2026 23:00:47 +0000 Subject: [PATCH 11/13] Implementing the solution for the function repeatStr --- Sprint-3/2-practice-tdd/repeat-str.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 3838c7b00..95d5ba025 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,5 +1,19 @@ -function repeatStr() { - return "hellohellohello"; +function repeatStr(str, count) { + if (count < 0) { + throw new Error("Count cannot be negative"); + } + + if (count === 0) { + return ""; + } + + let result = ""; + + for (let i = 0; i < count; i++) { + result += str; + } + + return result; } module.exports = repeatStr; From 86215d39dbaa3a0db74544e58c65e782f5e2da92 Mon Sep 17 00:00:00 2001 From: KayanatSuleman Date: Fri, 20 Feb 2026 23:05:51 +0000 Subject: [PATCH 12/13] Adding jest test case for throw an error for negative count --- Sprint-3/2-practice-tdd/repeat-str.test.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index 5dbec6b20..d8ac47f52 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -27,8 +27,13 @@ test("should return the original string when count is 1", () => { // 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 empty string when count is 0", () => { + expect(repeatStr("hello", 0)).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 for negative count", () => { + expect(() => repeatStr("hello", -1)).toThrow("Count cannot be negative"); +}); \ No newline at end of file From 2239ca4274fe7ac57172738736c59d012abeeec6 Mon Sep 17 00:00:00 2001 From: KayanatSuleman Date: Sun, 22 Feb 2026 20:40:12 +0000 Subject: [PATCH 13/13] Remove Sprint-1 1-count.js from practice-tdd branch --- Sprint-1/1-key-exercises/1-count.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index e1ca0860c..117bcb2b6 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -2,10 +2,5 @@ let count = 0; count = count + 1; -console.log(count); // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing -// The '=' assignment operator. It assigns the value on the right hand side to the variable on the left. -// The variable 'count' is initially assigned the value of 0. -// And the result is assigned back to count. -// This mean 'count; is updated each time this line runs. \ No newline at end of file