From 38dbbd8a21432f4a1400ced1489ce18e22346be8 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Wed, 14 Oct 2026 22:59:38 +0100 Subject: [PATCH 01/44] Add test with different string length, it fails --- practice-tdd/count.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index cb3aaae59..ced811c00 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -17,6 +17,13 @@ test("should count multiple occurrences of a character", () => { expect(count).toEqual(5); }); +test("should count multiple occurrences of a character, any string length", () => { + const str = "aaaaaa"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(6); +}); + // Scenario: No Occurrences // Given the input string `str`, // And a character `char` that does not exist within `str`. From 6b5df279c95ea2220d0c1588e3da5c8eb8d46fc9 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Wed, 14 Oct 2026 23:00:34 +0100 Subject: [PATCH 02/44] Refactor countChar to make prev test pass --- practice-tdd/count.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice-tdd/count.js b/practice-tdd/count.js index 5518c5712..ad8bbf53c 100644 --- a/practice-tdd/count.js +++ b/practice-tdd/count.js @@ -1,3 +1,3 @@ export function countChar(stringOfCharacters, findCharacter) { - return 5 + return stringOfCharacters.length; } From ffcf1f953a182171e7b506dc63c7f8d46758507f Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Wed, 14 Oct 2026 23:02:32 +0100 Subject: [PATCH 03/44] Add test for varying chars in string, it fails --- practice-tdd/count.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index ced811c00..ccf947605 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -24,6 +24,13 @@ test("should count multiple occurrences of a character, any string length", () = expect(count).toEqual(6); }); +test("any string length, varying chars in string", () => { + const str = "aaabaaa"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(6); +}); + // Scenario: No Occurrences // Given the input string `str`, // And a character `char` that does not exist within `str`. From 9f80255a0d73c61b3bc30841a975d60c302d76e5 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Wed, 14 Oct 2026 23:07:06 +0100 Subject: [PATCH 04/44] Refactor countChar to make prev test pass --- practice-tdd/count.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/practice-tdd/count.js b/practice-tdd/count.js index ad8bbf53c..bdb01ae53 100644 --- a/practice-tdd/count.js +++ b/practice-tdd/count.js @@ -1,3 +1,12 @@ export function countChar(stringOfCharacters, findCharacter) { - return stringOfCharacters.length; + + let numOfa = 0; + + for (let i = 0; i < stringOfCharacters.length; i++) { + if (stringOfCharacters.charAt(i) === "a") { + numOfa++; + } + } + + return numOfa; } From b7fcec6e6fa7f8e83cd7fd04c21ea11ed146e3d3 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 13:48:02 +0100 Subject: [PATCH 05/44] Add test for any char that exists in string, it fails --- practice-tdd/count.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index ccf947605..8cfbdeef4 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -31,6 +31,13 @@ test("any string length, varying chars in string", () => { expect(count).toEqual(6); }); +test("any string length, varying chars in string, any char in string", () => { + const str = "aaabaaa"; + const char = "b"; + const count = countChar(str, char); + expect(count).toEqual(1); +}); + // Scenario: No Occurrences // Given the input string `str`, // And a character `char` that does not exist within `str`. From 626f314328c0601e8da6e4016ada401b5524e176 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 14:17:20 +0100 Subject: [PATCH 06/44] Refactor countChar to make prev test pass --- practice-tdd/count.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice-tdd/count.js b/practice-tdd/count.js index bdb01ae53..9022284c8 100644 --- a/practice-tdd/count.js +++ b/practice-tdd/count.js @@ -3,7 +3,7 @@ export function countChar(stringOfCharacters, findCharacter) { let numOfa = 0; for (let i = 0; i < stringOfCharacters.length; i++) { - if (stringOfCharacters.charAt(i) === "a") { + if (stringOfCharacters.charAt(i) === findCharacter) { numOfa++; } } From b1846611a1e801ce51a64cf298a87bb809e4ce69 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 14:19:48 +0100 Subject: [PATCH 07/44] Add test for char NOT in string, returns 0, test passes already --- practice-tdd/count.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index 8cfbdeef4..18b23dbe8 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -43,3 +43,10 @@ test("any string length, varying chars in string, any char in string", () => { // 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("any string length, varying chars in string, char NOT in string", () => { + const str = "aaabaaa"; + const char = "c"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); \ No newline at end of file From e59481e7fdbda1722bd7ac7695b363539ebe2151 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 14:29:43 +0100 Subject: [PATCH 08/44] Add test for count is 1, str is 'hello', it fails --- practice-tdd/repeat-str.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index 8a7036102..fbb482cf4 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -21,6 +21,13 @@ test("should repeat the string count times", () => { // 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, From ce8ef8811f76275321b0ca24991e46962100fb7c Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 14:31:55 +0100 Subject: [PATCH 09/44] Refactor repeatStr to pass prev test --- practice-tdd/repeat-str.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js index af273f3b0..ac12f2aeb 100644 --- a/practice-tdd/repeat-str.js +++ b/practice-tdd/repeat-str.js @@ -1,5 +1,3 @@ -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) { + return count === 1 ? "hello" : "hellohellohello"; } From 3da27c921345089792f634ab96d721d733a7df9b Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 14:34:05 +0100 Subject: [PATCH 10/44] Add test for count is 0, str is 'hello', should return empty string, test fails --- practice-tdd/repeat-str.test.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index fbb482cf4..8c0964dba 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -21,7 +21,7 @@ test("should repeat the string count times", () => { // 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", () => { +test("should repeat 'hello' 1 time", () => { const str = "hello"; const count = 1; const repeatedStr = repeatStr(str, count); @@ -33,6 +33,13 @@ test("should repeat the string count times", () => { // When the repeatStr function is called with these inputs, // Then it should return an empty string. +test("should return empty string, count is 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`, // When the repeatStr function is called with these inputs, From ece5aaf6f1ef45f296cf6993a91306155fd580ec Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 14:42:42 +0100 Subject: [PATCH 11/44] Refactor repeatStr to pass prev test --- practice-tdd/repeat-str.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js index ac12f2aeb..aa40c36a7 100644 --- a/practice-tdd/repeat-str.js +++ b/practice-tdd/repeat-str.js @@ -1,3 +1,12 @@ export function repeatStr(str, count) { - return count === 1 ? "hello" : "hellohellohello"; + + let repeatedStr = ""; + + if (count === 1){ + repeatedStr = 'hello'; + } else if (count === 3){ + repeatedStr = 'hellohellohello'; + } + + return repeatedStr; } From 41c6f5810fe065860235fd49c4b372680debac9c Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 14:44:15 +0100 Subject: [PATCH 12/44] Add test for count is 4, test fails --- practice-tdd/repeat-str.test.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index 8c0964dba..05b6d2e00 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -9,13 +9,20 @@ import { repeatStr } from "./repeat-str.js"; // When the repeatStr function is called with these inputs, // Then it should return a string that contains the original `str` repeated `count` times. -test("should repeat the string count times", () => { +test("should repeat the string count times, count is 3", () => { const str = "hello"; const count = 3; const repeatedStr = repeatStr(str, count); expect(repeatedStr).toEqual("hellohellohello"); }); +test("should repeat the string count times, count is 4", () => { + const str = "hello"; + const count = 4; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("hellohellohellohello"); +}); + // Case: handle count of 1: // Given a target string `str` and a `count` equal to 1, // When the repeatStr function is called with these inputs, From c4ed549de0cee76c0da16dbd63e895dda762ae25 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 14:45:49 +0100 Subject: [PATCH 13/44] Refactor repeatStr to be dynamic, and pass prev test --- practice-tdd/repeat-str.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js index aa40c36a7..63e3ff686 100644 --- a/practice-tdd/repeat-str.js +++ b/practice-tdd/repeat-str.js @@ -2,10 +2,8 @@ export function repeatStr(str, count) { let repeatedStr = ""; - if (count === 1){ - repeatedStr = 'hello'; - } else if (count === 3){ - repeatedStr = 'hellohellohello'; + for (let i=0; i Date: Thu, 15 Oct 2026 20:48:45 +0100 Subject: [PATCH 14/44] Add test for count is negative, should throw error, test fails --- practice-tdd/repeat-str.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index 05b6d2e00..5a7d150b8 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -51,3 +51,10 @@ test("should return empty string, count is 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 error, count is negative", () => { + const str = "hello"; + const count = -1; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toThrow(); +}); \ No newline at end of file From d8bc6e08cfc7078596cde436879a46b45ca7d414 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 21:42:25 +0100 Subject: [PATCH 15/44] Refactor repeatString to throw error and refactor the test, it passes --- practice-tdd/repeat-str.js | 5 +++++ practice-tdd/repeat-str.test.js | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js index 63e3ff686..b1710f5ef 100644 --- a/practice-tdd/repeat-str.js +++ b/practice-tdd/repeat-str.js @@ -1,5 +1,10 @@ export function repeatStr(str, count) { + if (count < 0){ + //console.log("hi"); + throw new Error("/Error: count should be non negative integer/"); + } + let repeatedStr = ""; for (let i=0; i { test("should throw error, count is negative", () => { const str = "hello"; const count = -1; - const repeatedStr = repeatStr(str, count); - expect(repeatedStr).toThrow(); + expect(() => { + repeatStr(str, count); + }).toThrow("/Error: count should be non negative integer/"); }); \ No newline at end of file From 43522a07d0bd739b1eae1701b5399cdf869753a5 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 21:44:23 +0100 Subject: [PATCH 16/44] Add test for dynamic string value, it fails --- practice-tdd/repeat-str.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index d67aaae6f..89adbe484 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -23,6 +23,13 @@ test("should repeat the string count times, count is 4", () => { expect(repeatedStr).toEqual("hellohellohellohello"); }); +test("should repeat the string count times, count is 3, any string", () => { + const str = "Orb"; + const count = 3; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("OrbOrbOrb"); +}); + // Case: handle count of 1: // Given a target string `str` and a `count` equal to 1, // When the repeatStr function is called with these inputs, From 54e7f2e4b883bdea7812a5cf0116efae77d22c80 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 21:45:19 +0100 Subject: [PATCH 17/44] Refactor repeatStr to use dynamic string in output, prev test now passes --- practice-tdd/repeat-str.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js index b1710f5ef..a0c3276f5 100644 --- a/practice-tdd/repeat-str.js +++ b/practice-tdd/repeat-str.js @@ -1,14 +1,13 @@ export function repeatStr(str, count) { if (count < 0){ - //console.log("hi"); throw new Error("/Error: count should be non negative integer/"); } let repeatedStr = ""; for (let i=0; i Date: Thu, 15 Oct 2026 22:13:58 +0100 Subject: [PATCH 18/44] Refactor function to pass the failing tests --- practice-tdd/get-ordinal-number.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index 5c6291f5e..aa57c058e 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -1,3 +1,3 @@ export function getOrdinalNumber(num) { - return "1st"; + return num + "st"; } From 6721f24df4e1de7f3414bb24cc3b6200d80d5081 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 22:17:33 +0100 Subject: [PATCH 19/44] Add tests for numbers ending with 11, they fail --- 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 e23174a18..ee988f332 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -18,3 +18,10 @@ 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: Numbers ending with 11. Should append "th" to the number +test("should append 'th' for numbers ending with 11", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(111)).toEqual("111th"); + expect(getOrdinalNumber(4211)).toEqual("4211th"); +}); \ No newline at end of file From 582352fcb7b8bd1848347d42326258e12d5e3d55 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 22:30:25 +0100 Subject: [PATCH 20/44] Refactor function to pass prev tests --- practice-tdd/get-ordinal-number.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index aa57c058e..1bd512ec2 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -1,3 +1,11 @@ export function getOrdinalNumber(num) { - return num + "st"; + + if ((num - 11) % 100 === 0){ + return num + "th"; + } + + if ((num - 1) % 10 === 0){ + return num + "st"; + } + } From ed6c46c5eb181162cc4ca504678313139bb5d0d5 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 22:32:42 +0100 Subject: [PATCH 21/44] Add tests for number ending 2 but not 12, they fail --- 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 ee988f332..a351ba879 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -24,4 +24,11 @@ test("should append 'th' for numbers ending with 11", () => { expect(getOrdinalNumber(11)).toEqual("11th"); expect(getOrdinalNumber(111)).toEqual("111th"); expect(getOrdinalNumber(4211)).toEqual("4211th"); +}); + +// Case 3: Numbers ending with 2 (but not 12). Should append "nd" to the number +test("should append 'nd' for numbers ending with 2, except those ending with 12", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(22)).toEqual("22nd"); + expect(getOrdinalNumber(132)).toEqual("132nd"); }); \ No newline at end of file From 8ad33fcbe48969e74aa21a4fd27a124a15260d69 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 22:33:33 +0100 Subject: [PATCH 22/44] Refactor function to pass prev tests --- 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 1bd512ec2..bd2b7cb01 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -8,4 +8,8 @@ export function getOrdinalNumber(num) { return num + "st"; } + if ((num - 2) % 10 === 0){ + return num + "nd" + } + } From b21915a789897aca7ac5addcb493800e309f9958 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 22:34:40 +0100 Subject: [PATCH 23/44] Add tests for numbers ending with 12, they fail --- 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 a351ba879..dd2c9ab58 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -31,4 +31,11 @@ test("should append 'nd' for numbers ending with 2, except those ending with 12" expect(getOrdinalNumber(2)).toEqual("2nd"); expect(getOrdinalNumber(22)).toEqual("22nd"); expect(getOrdinalNumber(132)).toEqual("132nd"); +}); + +// Case 4: Numbers ending with 12. Should append "th" to the number +test("should append 'th' for numbers ending with 12", () => { + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(112)).toEqual("112th"); + expect(getOrdinalNumber(4212)).toEqual("4212th"); }); \ No newline at end of file From 4ef1b434272f06bac4da58349a0c384234c0f40c Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 22:35:13 +0100 Subject: [PATCH 24/44] Refactor function to pass prev tests --- 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 bd2b7cb01..52255ea93 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -8,6 +8,10 @@ export function getOrdinalNumber(num) { return num + "st"; } + if ((num - 12) % 100 === 0) { + return num + "th"; + } + if ((num - 2) % 10 === 0){ return num + "nd" } From 8d41b972cd90d014b7bed2c6d834f63f454d58c5 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 22:36:35 +0100 Subject: [PATCH 25/44] Add tests for numbers ending 3 but not 13, they fail --- 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 dd2c9ab58..77a9eb811 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -38,4 +38,11 @@ test("should append 'th' for numbers ending with 12", () => { expect(getOrdinalNumber(12)).toEqual("12th"); expect(getOrdinalNumber(112)).toEqual("112th"); expect(getOrdinalNumber(4212)).toEqual("4212th"); +}); + +// Case 5: Numbers ending with 3 (but not 13). Should append "rd" to the number +test("should append 'nd' for numbers ending with 2, except those ending with 12", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(23)).toEqual("23rd"); + expect(getOrdinalNumber(133)).toEqual("133rd"); }); \ No newline at end of file From 719b29d38a6fc91e3c94d1d50e90a5ebd7f82a0a Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 22:37:11 +0100 Subject: [PATCH 26/44] Refactor function to pass prev tests --- 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 52255ea93..8796f5693 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -16,4 +16,8 @@ export function getOrdinalNumber(num) { return num + "nd" } + if ((num - 3) % 10 === 0) { + return num + "rd"; + } + } From c4fa2c666178566ec2cf3376db0b867e2e4e6803 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 22:37:59 +0100 Subject: [PATCH 27/44] Add tests for numbers ending 13, they fail --- 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 77a9eb811..4f40e1d80 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -45,4 +45,11 @@ test("should append 'nd' for numbers ending with 2, except those ending with 12" expect(getOrdinalNumber(3)).toEqual("3rd"); expect(getOrdinalNumber(23)).toEqual("23rd"); expect(getOrdinalNumber(133)).toEqual("133rd"); +}); + +// Case 6: Numbers ending with 13. Should append "th" to the number +test("should append 'th' for numbers ending with 12", () => { + expect(getOrdinalNumber(13)).toEqual("13th"); + expect(getOrdinalNumber(113)).toEqual("113th"); + expect(getOrdinalNumber(4213)).toEqual("4213th"); }); \ No newline at end of file From 5c15ff49945f11cf6f1adf6123d8bb13aa95c79c Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 22:38:39 +0100 Subject: [PATCH 28/44] Refactor function to pass prev tests --- 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 8796f5693..7f645f70c 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -16,6 +16,10 @@ export function getOrdinalNumber(num) { return num + "nd" } + if ((num - 13) % 100 === 0) { + return num + "th"; + } + if ((num - 3) % 10 === 0) { return num + "rd"; } From 7b78cddc97ee488ea631436389a4494c812b7739 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 22:42:32 +0100 Subject: [PATCH 29/44] Add tests for all other whole numbers, they fail --- 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 4f40e1d80..4caa92509 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -52,4 +52,11 @@ test("should append 'th' for numbers ending with 12", () => { expect(getOrdinalNumber(13)).toEqual("13th"); expect(getOrdinalNumber(113)).toEqual("113th"); expect(getOrdinalNumber(4213)).toEqual("4213th"); +}); + +// Case 7: All other whole numbers. Should append "th" to the number +test("should append 'th' for numbers ending with 12", () => { + expect(getOrdinalNumber(-1834)).toEqual("-1834th"); + expect(getOrdinalNumber(23151509)).toEqual("23151509th"); + expect(getOrdinalNumber(-100)).toEqual("-100th"); }); \ No newline at end of file From eae160f82318f2abf8413ee93ff76513d1d6f625 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Thu, 15 Oct 2026 22:42:56 +0100 Subject: [PATCH 30/44] Refactor function to pass prev tests --- 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 7f645f70c..dbb7ceded 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -24,4 +24,6 @@ export function getOrdinalNumber(num) { return num + "rd"; } + return num + "th"; + } From c032f5bb19ad58ff11e54c60c556b54f400cf2e4 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Fri, 16 Oct 2026 11:07:49 +0100 Subject: [PATCH 31/44] Add test for throwing error when decimal number passed. Test fails --- practice-tdd/get-ordinal-number.test.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index 4caa92509..b3bbe8681 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -55,8 +55,13 @@ test("should append 'th' for numbers ending with 12", () => { }); // Case 7: All other whole numbers. Should append "th" to the number -test("should append 'th' for numbers ending with 12", () => { +test("should append 'th' for all other whole numbers", () => { expect(getOrdinalNumber(-1834)).toEqual("-1834th"); expect(getOrdinalNumber(23151509)).toEqual("23151509th"); expect(getOrdinalNumber(-100)).toEqual("-100th"); +}); + +// Case 8: Throw error for invalid numbers +test("should throw error for all invalid numbers", () => { + expect(() => {getOrdinalNumber(5.7)}).toThrow("Error: whole number is needed"); }); \ No newline at end of file From 8614766e8c42ddea09fbf311a66b768c1f94fadf Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Fri, 16 Oct 2026 11:08:34 +0100 Subject: [PATCH 32/44] Refactor function to pass prev test --- 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 dbb7ceded..125b908e9 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -1,5 +1,9 @@ export function getOrdinalNumber(num) { + if (num % 1 !== 0) { + throw new Error("Error: whole number is needed"); + } + if ((num - 11) % 100 === 0){ return num + "th"; } From 8c543034b89665bb1cf5527bdcd6b7ca4273897b Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Fri, 16 Oct 2026 11:10:33 +0100 Subject: [PATCH 33/44] Add test for missing argument, it passes on the same premise as the last test --- practice-tdd/get-ordinal-number.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index b3bbe8681..712f52b7b 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -64,4 +64,7 @@ test("should append 'th' for all other whole numbers", () => { // Case 8: Throw error for invalid numbers test("should throw error for all invalid numbers", () => { expect(() => {getOrdinalNumber(5.7)}).toThrow("Error: whole number is needed"); + expect(() => { + getOrdinalNumber(); + }).toThrow("Error: whole number is needed"); }); \ No newline at end of file From 74f5c3372fe9427f6b314c65c18badf09850dff2 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Fri, 16 Oct 2026 11:11:47 +0100 Subject: [PATCH 34/44] Add test for a passed string, it also passes thanks to the same check --- practice-tdd/get-ordinal-number.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index 712f52b7b..305886329 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -67,4 +67,7 @@ test("should throw error for all invalid numbers", () => { expect(() => { getOrdinalNumber(); }).toThrow("Error: whole number is needed"); + expect(() => { + getOrdinalNumber("hey"); + }).toThrow("Error: whole number is needed"); }); \ No newline at end of file From 23e9048ca72a974ba3bf266abcefe95d024eabf6 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Fri, 16 Oct 2026 11:12:25 +0100 Subject: [PATCH 35/44] Add test for undefined, it passes as well due to the same reason --- practice-tdd/get-ordinal-number.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index 305886329..1729fd3f4 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -70,4 +70,7 @@ test("should throw error for all invalid numbers", () => { expect(() => { getOrdinalNumber("hey"); }).toThrow("Error: whole number is needed"); + expect(() => { + getOrdinalNumber(undefined); + }).toThrow("Error: whole number is needed"); }); \ No newline at end of file From 803ce36cbe1d2422cc9df2e724fbbbd3fc193be9 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Fri, 16 Oct 2026 11:13:21 +0100 Subject: [PATCH 36/44] Add test for num is null to throw error, it fails --- practice-tdd/get-ordinal-number.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index 1729fd3f4..a539ca2c0 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -73,4 +73,7 @@ test("should throw error for all invalid numbers", () => { expect(() => { getOrdinalNumber(undefined); }).toThrow("Error: whole number is needed"); + expect(() => { + getOrdinalNumber(null); + }).toThrow("Error: whole number is needed"); }); \ No newline at end of file From 5a8d70f28a3bd9a9309a73b5d74688339fe6dad1 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Fri, 16 Oct 2026 11:14:00 +0100 Subject: [PATCH 37/44] Refactor function to pass prev test --- practice-tdd/get-ordinal-number.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index 125b908e9..7e5c4b759 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -1,6 +1,6 @@ export function getOrdinalNumber(num) { - if (num % 1 !== 0) { + if (num % 1 !== 0 || !num) { throw new Error("Error: whole number is needed"); } From ceaec78203a64b34fa195002dfac1b617735c962 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Fri, 16 Oct 2026 11:14:38 +0100 Subject: [PATCH 38/44] Add test for num is false should throw error, it passes --- practice-tdd/get-ordinal-number.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index a539ca2c0..259b0a1a9 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -76,4 +76,7 @@ test("should throw error for all invalid numbers", () => { expect(() => { getOrdinalNumber(null); }).toThrow("Error: whole number is needed"); + expect(() => { + getOrdinalNumber(false); + }).toThrow("Error: whole number is needed"); }); \ No newline at end of file From 63998f9c115a201b2bcbef978064bb19c8bcd8cb Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Fri, 16 Oct 2026 11:15:32 +0100 Subject: [PATCH 39/44] Add test for num is true to throw error, it fails --- practice-tdd/get-ordinal-number.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index 259b0a1a9..3f343cbf3 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -79,4 +79,7 @@ test("should throw error for all invalid numbers", () => { expect(() => { getOrdinalNumber(false); }).toThrow("Error: whole number is needed"); + expect(() => { + getOrdinalNumber(true); + }).toThrow("Error: whole number is needed"); }); \ No newline at end of file From 0aa534c8080c3ee814f66c91b5dcc2acb1dd861e Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Fri, 16 Oct 2026 11:17:40 +0100 Subject: [PATCH 40/44] Refactor function to pass prev test --- practice-tdd/get-ordinal-number.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index 7e5c4b759..1f5ae4e43 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -1,6 +1,6 @@ export function getOrdinalNumber(num) { - if (num % 1 !== 0 || !num) { + if (num % 1 !== 0 || !num || (typeof num) !== "number") { throw new Error("Error: whole number is needed"); } From 1724b9a2d06e73ba77e9d232cd60b8be50acba21 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Fri, 16 Oct 2026 11:18:39 +0100 Subject: [PATCH 41/44] Add test for num is array to throw error, it fails --- practice-tdd/get-ordinal-number.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index 3f343cbf3..54438738a 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -82,4 +82,7 @@ test("should throw error for all invalid numbers", () => { expect(() => { getOrdinalNumber(true); }).toThrow("Error: whole number is needed"); + expect(() => { + getOrdinalNumber([1,2,3]); + }).toThrow("Error: whole number is needed"); }); \ No newline at end of file From 330bd0839eb10278088dab5084131e128511b5ec Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Fri, 16 Oct 2026 11:19:13 +0100 Subject: [PATCH 42/44] Refactor function to pass prev test --- practice-tdd/get-ordinal-number.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index 1f5ae4e43..7a27c14fe 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -1,6 +1,6 @@ export function getOrdinalNumber(num) { - if (num % 1 !== 0 || !num || (typeof num) !== "number") { + if (num % 1 !== 0 || !num || (typeof num) !== "number" || num.length > 1) { throw new Error("Error: whole number is needed"); } From 957410123086bf1ed7546c260adbe46e5573162f Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Fri, 16 Oct 2026 11:20:24 +0100 Subject: [PATCH 43/44] Add test for num is object to throw error, it passes --- practice-tdd/get-ordinal-number.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index 54438738a..5c0e50b94 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -85,4 +85,7 @@ test("should throw error for all invalid numbers", () => { expect(() => { getOrdinalNumber([1,2,3]); }).toThrow("Error: whole number is needed"); + expect(() => { + getOrdinalNumber({4: 'hey', 'bye': 39}); + }).toThrow("Error: whole number is needed"); }); \ No newline at end of file From c939e5770bff6182f919e2c68b66ef49448856c2 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Fri, 16 Oct 2026 11:24:01 +0100 Subject: [PATCH 44/44] Format files with prettier --- practice-tdd/count.js | 1 - practice-tdd/count.test.js | 2 +- practice-tdd/get-ordinal-number.js | 12 +++++------- practice-tdd/get-ordinal-number.test.js | 10 ++++++---- practice-tdd/repeat-str.js | 5 ++--- practice-tdd/repeat-str.test.js | 2 +- 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/practice-tdd/count.js b/practice-tdd/count.js index 9022284c8..bc055f3e5 100644 --- a/practice-tdd/count.js +++ b/practice-tdd/count.js @@ -1,5 +1,4 @@ export function countChar(stringOfCharacters, findCharacter) { - let numOfa = 0; for (let i = 0; i < stringOfCharacters.length; i++) { diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index 18b23dbe8..2e4ac2d53 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -49,4 +49,4 @@ test("any string length, varying chars in string, char NOT in string", () => { const char = "c"; const count = countChar(str, char); expect(count).toEqual(0); -}); \ No newline at end of file +}); diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index 7a27c14fe..edc44d340 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -1,14 +1,13 @@ export function getOrdinalNumber(num) { - - if (num % 1 !== 0 || !num || (typeof num) !== "number" || num.length > 1) { + if (num % 1 !== 0 || !num || typeof num !== "number" || num.length > 1) { throw new Error("Error: whole number is needed"); } - if ((num - 11) % 100 === 0){ + if ((num - 11) % 100 === 0) { return num + "th"; } - if ((num - 1) % 10 === 0){ + if ((num - 1) % 10 === 0) { return num + "st"; } @@ -16,8 +15,8 @@ export function getOrdinalNumber(num) { return num + "th"; } - if ((num - 2) % 10 === 0){ - return num + "nd" + if ((num - 2) % 10 === 0) { + return num + "nd"; } if ((num - 13) % 100 === 0) { @@ -29,5 +28,4 @@ export function getOrdinalNumber(num) { } return num + "th"; - } diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index 5c0e50b94..d547e1d16 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -63,7 +63,9 @@ test("should append 'th' for all other whole numbers", () => { // Case 8: Throw error for invalid numbers test("should throw error for all invalid numbers", () => { - expect(() => {getOrdinalNumber(5.7)}).toThrow("Error: whole number is needed"); + expect(() => { + getOrdinalNumber(5.7); + }).toThrow("Error: whole number is needed"); expect(() => { getOrdinalNumber(); }).toThrow("Error: whole number is needed"); @@ -83,9 +85,9 @@ test("should throw error for all invalid numbers", () => { getOrdinalNumber(true); }).toThrow("Error: whole number is needed"); expect(() => { - getOrdinalNumber([1,2,3]); + getOrdinalNumber([1, 2, 3]); }).toThrow("Error: whole number is needed"); expect(() => { - getOrdinalNumber({4: 'hey', 'bye': 39}); + getOrdinalNumber({ 4: "hey", bye: 39 }); }).toThrow("Error: whole number is needed"); -}); \ No newline at end of file +}); diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js index a0c3276f5..a6ed87a28 100644 --- a/practice-tdd/repeat-str.js +++ b/practice-tdd/repeat-str.js @@ -1,12 +1,11 @@ export function repeatStr(str, count) { - - if (count < 0){ + if (count < 0) { throw new Error("/Error: count should be non negative integer/"); } let repeatedStr = ""; - for (let i=0; i { expect(() => { repeatStr(str, count); }).toThrow("/Error: count should be non negative integer/"); -}); \ No newline at end of file +});