From 02f9da3d62911a38b60e4497bfbf70afd7e3b24d Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Sat, 1 Aug 2026 15:29:29 +0100 Subject: [PATCH 1/2] Work on sprint 3 1-get-angle-type put in code using "if" function. --- Sprint-3/2-practice-tdd/count.js | 12 ++++++++++-- Sprint-3/2-practice-tdd/count.test.js | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..cd9d2d9348 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,13 @@ +// function countChar(stringOfCharacters, findCharacter) { +// return 5 +// } function countChar(stringOfCharacters, findCharacter) { - return 5 + let countChar = 0; + for (let stringNum = 0; stringNum < stringOfCharacters.length; stringNum++) { + if (findCharacter === stringOfCharacters[stringNum]){ + countChar++ + } + } + return countChar } - module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf7..b5761020b0 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -17,8 +17,29 @@ test("should count multiple occurrences of a character", () => { expect(count).toEqual(5); }); +test("should count multiple occurrences of a character", () => { + const str = "aaa aa"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(5); +}); + +test("should count multiple occurrences of a character with random characters", () => { + const str = "ajhyabhaakaka"; + 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`. // 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 with no occurrence of the character", () => { + const str ="abcd"; + const char = "e"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); + From 1ca6ee18d5bfa95bffcb5dec16be8f3a6f9b8074 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Sat, 1 Aug 2026 16:09:35 +0100 Subject: [PATCH 2/2] SPrint 3- practice-tdd - get-ordinal-numbers Making of code and tests --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 11 ++++++++++- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 5 +++++ 2 files changed, 15 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 f95d71db13..ad65497f4a 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,14 @@ +// function getOrdinalNumber(num) { +// return "1st"; +// } + function getOrdinalNumber(num) { - return "1st"; + let text = num.toString(); + if (text === "11") { + return (text + "th"); + } + return (text + "st"); } +// getOrdinalNumber(1)).toEqual("1st") module.exports = getOrdinalNumber; diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js index adfa58560f..1cf5ac1d18 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -18,3 +18,8 @@ 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' for number 11", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); + +}); \ No newline at end of file