From 618504b04fc9efc3867bf7b2c40179f83c880e90 Mon Sep 17 00:00:00 2001 From: marscancode Date: Sat, 17 Oct 2026 16:04:04 +0100 Subject: [PATCH 01/20] added countChar test for when character does not occur, it fails --- practice-tdd/count.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index cb3aaae59..7f603e40e 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -22,3 +22,9 @@ 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 return 0 when character does not occur", () => { + const str = "aaaabcd"; + const char = "e"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); From 833d950cbdc23b174ced590039ca59861c83ae9a Mon Sep 17 00:00:00 2001 From: marscancode Date: Sat, 17 Oct 2026 16:44:17 +0100 Subject: [PATCH 02/20] implemented countChar function, tests now pass --- practice-tdd/count.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/practice-tdd/count.js b/practice-tdd/count.js index 5518c5712..ffdb077ed 100644 --- a/practice-tdd/count.js +++ b/practice-tdd/count.js @@ -1,3 +1,10 @@ export function countChar(stringOfCharacters, findCharacter) { - return 5 + let count = 0; + + for (let i = 0; i < stringOfCharacters.length; i++) { + if (stringOfCharacters[i] === findCharacter) { + count++; + } + } + return count; } From dc8d57f5e185370769e8e2019bec6b4545385358 Mon Sep 17 00:00:00 2001 From: marscancode Date: Sat, 17 Oct 2026 17:08:56 +0100 Subject: [PATCH 03/20] added repeatStr test for when count is 1 --- practice-tdd/repeat-str.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index 8a7036102..5a4a9aaf1 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -20,6 +20,12 @@ 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 equals 1", () => { + const str = "hello"; + const count = 1; + const repeatedStr = repeatStr(str, count); + expect(repeatStr).toEqual("hello"); +}); // Case: Handle count of 0: // Given a target string `str` and a `count` equal to 0, From dccf8e33e8a81a09ae4718929c4ca9a59d6d8aad Mon Sep 17 00:00:00 2001 From: marscancode Date: Sat, 17 Oct 2026 17:36:47 +0100 Subject: [PATCH 04/20] fixed spelling error in test --- practice-tdd/repeat-str.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index 5a4a9aaf1..007c5bcca 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -24,7 +24,7 @@ test("should return the original string when count equals 1", () => { const str = "hello"; const count = 1; const repeatedStr = repeatStr(str, count); - expect(repeatStr).toEqual("hello"); + expect(repeatedStr).toEqual("hello"); }); // Case: Handle count of 0: From c47e4e009a14d1e98a3cf2c55115dc74bf445548 Mon Sep 17 00:00:00 2001 From: marscancode Date: Sat, 17 Oct 2026 17:37:38 +0100 Subject: [PATCH 05/20] implemented repeatStr function, test now passes --- practice-tdd/repeat-str.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js index af273f3b0..56d2226c9 100644 --- a/practice-tdd/repeat-str.js +++ b/practice-tdd/repeat-str.js @@ -1,5 +1,7 @@ -export 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"; +export function repeatStr(str, count) { + let result = ""; + for (let i = 0; i < count; i++) { + result += str; + } + return result; } From 3f2d32ab295721ede3b59a977e80d6d7817dc2c6 Mon Sep 17 00:00:00 2001 From: marscancode Date: Sat, 17 Oct 2026 17:48:15 +0100 Subject: [PATCH 06/20] added repeatStr test to check it returns an empty string when count is 0 --- practice-tdd/repeat-str.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index 007c5bcca..3db57c5af 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -31,6 +31,12 @@ test("should return the original string when count equals 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 an empty string when count equals 0", () => { + 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`, From 74a438d16ba5d659f44729c760622bd47d722efd Mon Sep 17 00:00:00 2001 From: marscancode Date: Sat, 17 Oct 2026 17:55:18 +0100 Subject: [PATCH 07/20] added test to check if repeatStr throws an error when count is 0 --- practice-tdd/repeat-str.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index 3db57c5af..35ae5c13c 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -42,3 +42,8 @@ test("should return an empty string when count equals 0", () => { // 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 when count is a negative number", () => { + const str = hello; + const count = -2; + expect(() => repeatStr(str, count)).toThrow(); +}); From 857468b2fc8bfea8c23b65d1157e7e48c480c8b9 Mon Sep 17 00:00:00 2001 From: marscancode Date: Sat, 17 Oct 2026 18:05:27 +0100 Subject: [PATCH 08/20] fixed syntax error in when count is negative test, test fails --- practice-tdd/repeat-str.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index 35ae5c13c..fce69a7e9 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -43,7 +43,7 @@ test("should return an empty string when count equals 0", () => { // 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 when count is a negative number", () => { - const str = hello; + const str = "hello"; const count = -2; expect(() => repeatStr(str, count)).toThrow(); }); From 141163d6ff3bfbc4054ccd1b84af97560fd80bd3 Mon Sep 17 00:00:00 2001 From: marscancode Date: Sat, 17 Oct 2026 18:46:37 +0100 Subject: [PATCH 09/20] implemented repeatStr with count error --- practice-tdd/repeat-str.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js index 56d2226c9..36828f586 100644 --- a/practice-tdd/repeat-str.js +++ b/practice-tdd/repeat-str.js @@ -1,4 +1,7 @@ export function repeatStr(str, count) { + if (count < 0) { + throw new Error("warning! Count cannot be negative!"); + } let result = ""; for (let i = 0; i < count; i++) { result += str; From 223c12082348b6d0488852a2426073acaf518aa9 Mon Sep 17 00:00:00 2001 From: marscancode Date: Sun, 18 Oct 2026 11:31:38 +0100 Subject: [PATCH 10/20] implemented getOrdinalNumber function to handle numbers ending in 1, tests now pass --- practice-tdd/get-ordinal-number.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index 5c6291f5e..2278a13f8 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -1,3 +1,5 @@ export function getOrdinalNumber(num) { - return "1st"; + if (num % 10 === 1) { + return `${num}st`; + } } From ffae1e7f1f1ced2dda382f30db8bfa8e0c703a52 Mon Sep 17 00:00:00 2001 From: marscancode Date: Sun, 18 Oct 2026 11:37:25 +0100 Subject: [PATCH 11/20] added test for getOrdinalNumber function to check if th gets added to number 11 --- practice-tdd/get-ordinal-number.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index e23174a18..3cab406e3 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -18,3 +18,7 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(131)).toEqual("131st"); }); + +test('should append "th" to number 11', () => { + expect(getOrdinalNumber(11)).toEqual("11th"); +}) From fb5170f03da4b1b32ba3bee71d493f6d29236a40 Mon Sep 17 00:00:00 2001 From: marscancode Date: Sun, 18 Oct 2026 11:46:16 +0100 Subject: [PATCH 12/20] implemented getOrdinalNumber function to handle numbers ending in 11, tests now pass --- practice-tdd/get-ordinal-number.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index 2278a13f8..7c0901368 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -1,5 +1,7 @@ export function getOrdinalNumber(num) { - if (num % 10 === 1) { - return `${num}st`; +if(num % 100 === 11){ + return `${num}th` +} else if(num % 10 === 1){ + return `${num}st` } } From 7c3e70698b717db7068301825bffdae74f6ebf5e Mon Sep 17 00:00:00 2001 From: marscancode Date: Sun, 18 Oct 2026 11:49:46 +0100 Subject: [PATCH 13/20] updated previous test wording to be more specific about numbers ending in 11 --- practice-tdd/get-ordinal-number.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index 3cab406e3..712d750b9 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -19,6 +19,6 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(131)).toEqual("131st"); }); -test('should append "th" to number 11', () => { +test('should append "th" to numbers ending in 11', () => { expect(getOrdinalNumber(11)).toEqual("11th"); -}) +}); From e5ba94773e6281fe100c659c753346e487d4835d Mon Sep 17 00:00:00 2001 From: marscancode Date: Sun, 18 Oct 2026 11:56:40 +0100 Subject: [PATCH 14/20] added test for numbers ending in 2, except 12, test fails --- practice-tdd/get-ordinal-number.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index 712d750b9..cf9dcc9a3 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -22,3 +22,9 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" test('should append "th" to numbers ending in 11', () => { expect(getOrdinalNumber(11)).toEqual("11th"); }); + +test('should append "nd" to numbers ending in 2, apart from those ending in 12', () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(32)).toEqual("32nd"); + expect(getOrdinalNumber(142)).toEqual("142nd"); +}); From 71037555ddade2e7f64d5b78db81a13fb8a74fbf Mon Sep 17 00:00:00 2001 From: marscancode Date: Sun, 18 Oct 2026 12:03:32 +0100 Subject: [PATCH 15/20] implemented getOrdinalNumber function to handle numbers ending in 12 and 2, tests now pass --- practice-tdd/get-ordinal-number.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index 7c0901368..2bd9f97c7 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -1,7 +1,11 @@ export function getOrdinalNumber(num) { -if(num % 100 === 11){ - return `${num}th` -} else if(num % 10 === 1){ - return `${num}st` + if (num % 100 === 11) { + return `${num}th`; + } else if (num % 10 === 1) { + return `${num}st`; + } else if (num % 100 === 12) { + return `${num}th`; + } else if (num % 10 === 2) { + return `${num}nd`; } } From 10424c5da26b969ba73fcc530515221d52def516 Mon Sep 17 00:00:00 2001 From: marscancode Date: Sun, 18 Oct 2026 12:11:21 +0100 Subject: [PATCH 16/20] added tests for numbers ending in 3, expect 13, tests fail --- practice-tdd/get-ordinal-number.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index cf9dcc9a3..00e8b1c83 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -28,3 +28,9 @@ test('should append "nd" to numbers ending in 2, apart from those ending in 12', expect(getOrdinalNumber(32)).toEqual("32nd"); expect(getOrdinalNumber(142)).toEqual("142nd"); }); + +test('should append "rd" to numbers ending in 3, apart from those ending in 13', () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(33)).toEqual("33rd"); + expect(getOrdinalNumber(143)).toEqual("143rd"); +}); From 8e97e3395759a04610f5d32224cc8d69b86f2463 Mon Sep 17 00:00:00 2001 From: marscancode Date: Sun, 18 Oct 2026 12:16:34 +0100 Subject: [PATCH 17/20] refactored tests to group 11, 12, and 13 as exceptions with th --- practice-tdd/get-ordinal-number.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index 00e8b1c83..6ae76c1cd 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -19,8 +19,10 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(131)).toEqual("131st"); }); -test('should append "th" to numbers ending in 11', () => { +test('should append "th" to numbers ending in 11, 12, or 13', () => { expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); }); test('should append "nd" to numbers ending in 2, apart from those ending in 12', () => { From 00f12298bf0606f56d50d686fd6fa151e3289265 Mon Sep 17 00:00:00 2001 From: marscancode Date: Sun, 18 Oct 2026 12:22:29 +0100 Subject: [PATCH 18/20] implemented getOrdinalNumber function to handle numbers ending in 13 and 3, tests now pass --- practice-tdd/get-ordinal-number.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index 2bd9f97c7..89570a7ee 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -7,5 +7,9 @@ export function getOrdinalNumber(num) { return `${num}th`; } else if (num % 10 === 2) { return `${num}nd`; + } else if (num % 100 === 13) { + return `${num}th`; + } else if (num % 10 === 3) { + return `${num}rd`; } } From b6b29b14382550fc017ae424ab545caf3c4f3a91 Mon Sep 17 00:00:00 2001 From: marscancode Date: Sun, 18 Oct 2026 12:33:53 +0100 Subject: [PATCH 19/20] added getOrdinalNumber tests for other numbers that don't end in 1, 2, or 3 --- practice-tdd/get-ordinal-number.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index 6ae76c1cd..bdcee5858 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -36,3 +36,10 @@ test('should append "rd" to numbers ending in 3, apart from those ending in 13', expect(getOrdinalNumber(33)).toEqual("33rd"); expect(getOrdinalNumber(143)).toEqual("143rd"); }); + +test(`should append "th" to other numbers that don't end in 1, 2, or 3`, () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(24)).toEqual("24th"); + expect(getOrdinalNumber(100)).toEqual("100th"); +}); From e8faea9e1bd95a08a206b3fce5945b946b7e2678 Mon Sep 17 00:00:00 2001 From: marscancode Date: Sun, 18 Oct 2026 12:38:39 +0100 Subject: [PATCH 20/20] implemented function to handle all other numbers that don't end in 1, 2, or 3 --- practice-tdd/get-ordinal-number.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index 89570a7ee..1d361428a 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -11,5 +11,7 @@ export function getOrdinalNumber(num) { return `${num}th`; } else if (num % 10 === 3) { return `${num}rd`; + } else { + return `${num}th`; } }