From 31f50ad84d12460cd87a1ac20948e02b686390f3 Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Thu, 6 Nov 2025 15:54:22 +0000 Subject: [PATCH 01/17] count.js updated --- Sprint-3/2-practice-tdd/count.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d..d22559ff9 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -3,3 +3,19 @@ function countChar(stringOfCharacters, findCharacter) { } module.exports = countChar; + +const countChar = require('../countChar'); + +describe('countChar()', () => { + test('always returns 5', () => { + expect(countChar('anything', 'a')).toBe(5); + }); + + test('still returns 5 with empty string', () => { + expect(countChar('', 'z')).toBe(5); + }); + + test('still returns 5 with special characters', () => { + expect(countChar('!!!', '!')).toBe(5); + }); +}); From a61f9b1abe9dea5aac3ac4507f95948c6116465a Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Thu, 6 Nov 2025 16:45:34 +0000 Subject: [PATCH 02/17] updated pr template --- Sprint-3/2-practice-tdd/count.test.js | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 42baf4b4b..a94c93701 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -16,6 +16,36 @@ test("should count multiple occurrences of a character", () => { const count = countChar(str, char); expect(count).toEqual(5); }); +test("should return 0 when the character is not found", () => { + const str = "hello"; + const char = "z"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); + +// Scenario: Case Sensitivity +// It should be case-sensitive, meaning 'A' != 'a'. +test("should be case-sensitive when counting characters", () => { + const str = "Banana"; + expect(countChar(str, "a")).toEqual(3); + expect(countChar(str, "A")).toEqual(0); +}); + +// Scenario: Empty String +// It should return 0 when the input string is empty. +test("should return 0 when the input string is empty", () => { + const str = ""; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); + +// Scenario: Special Characters +// It should correctly count spaces and punctuation. +test("should count special characters like spaces or punctuation", () => { + expect(countChar("a b a b", " ")).toEqual(2); + expect(countChar("wow!!!", "!")).toEqual(3); +}); // Scenario: No Occurrences // Given the input string str, From 2a422f5a25e64669d2d89d65cb0402fb758df15a Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Thu, 6 Nov 2025 16:47:59 +0000 Subject: [PATCH 03/17] updated PR template --- Sprint-3/2-practice-tdd/count.test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index a94c93701..1bf611fc3 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -1,5 +1,16 @@ // implement a function countChar that counts the number of times a character occurs in a string const countChar = require("./count"); + +function countChar(stringOfCharacters, findCharacter) { + let count = 0; + for (let char of stringOfCharacters) { + if (char === findCharacter) count++; + } + return count; +} + +module.exports = countChar; + // Given a string str and a single character char to search for, // When the countChar function is called with these inputs, // Then it should: From 04f5a7f8ee56748a989b8717d1bbc2c55f362c3b Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Thu, 6 Nov 2025 16:53:18 +0000 Subject: [PATCH 04/17] get ordinal numbers updated template --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 58 ++++++++++++++++++- 1 file changed, 57 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..318f08619 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,61 @@ + function getOrdinalNumber(num) { - return "1st"; + const remainder10 = num % 10; + const remainder100 = num % 100; + + if (remainder100 >= 11 && remainder100 <= 13) { + return `${num}th`; + } + + switch (remainder10) { + case 1: + return `${num}st`; + case 2: + return `${num}nd`; + case 3: + return `${num}rd`; + default: + return `${num}th`; + } } module.exports = getOrdinalNumber; + + +const getOrdinalNumber = require("./getOrdinalNumber"); + +describe("getOrdinalNumber()", () => { + test("should return '1st' for 1", () => { + expect(getOrdinalNumber(1)).toBe("1st"); + }); + + test("should return '2nd' for 2", () => { + expect(getOrdinalNumber(2)).toBe("2nd"); + }); + + test("should return '3rd' for 3", () => { + expect(getOrdinalNumber(3)).toBe("3rd"); + }); + + test("should return '4th' for 4", () => { + expect(getOrdinalNumber(4)).toBe("4th"); + }); + + test("should return '11th', '12th', '13th' for special cases", () => { + expect(getOrdinalNumber(11)).toBe("11th"); + expect(getOrdinalNumber(12)).toBe("12th"); + expect(getOrdinalNumber(13)).toBe("13th"); + }); + + test("should return correct suffixes for 21, 22, 23", () => { + expect(getOrdinalNumber(21)).toBe("21st"); + expect(getOrdinalNumber(22)).toBe("22nd"); + expect(getOrdinalNumber(23)).toBe("23rd"); + }); + + test("should return '111th' for numbers ending with 11, 12, 13 even if larger", () => { + expect(getOrdinalNumber(111)).toBe("111th"); + expect(getOrdinalNumber(112)).toBe("112th"); + expect(getOrdinalNumber(113)).toBe("113th"); + }); +}); From 7e9160de067f75480b16378d9e1e7294d945079b Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Thu, 6 Nov 2025 17:01:07 +0000 Subject: [PATCH 05/17] ordinal numbers updated PR template --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 7 +++++++ 1 file changed, 7 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 dfe4b6091..b3d6419f7 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -1,4 +1,11 @@ const getOrdinalNumber = require("./get-ordinal-number"); + +function getOrdinalNumber(num) { + return "1st"; +} + +module.exports = getOrdinalNumber; + // In this week's prep, we started implementing getOrdinalNumber // continue testing and implementing getOrdinalNumber for additional cases From 6c17f89d394e39dc8b106af75a2a7dbbec8b92c8 Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Thu, 6 Nov 2025 17:05:54 +0000 Subject: [PATCH 06/17] repeat.js updated template --- Sprint-3/2-practice-tdd/repeat.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-3/2-practice-tdd/repeat.js b/Sprint-3/2-practice-tdd/repeat.js index 00e60d7f3..125840b92 100644 --- a/Sprint-3/2-practice-tdd/repeat.js +++ b/Sprint-3/2-practice-tdd/repeat.js @@ -3,3 +3,7 @@ function repeat() { } module.exports = repeat; + +test("should repeat the given word three times", () => { + expect(repeat("hi", 3)).toBe("hihihi"); +}); From 94de70c2ac1de336a9cc76864e944dbe7ce19f48 Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Thu, 6 Nov 2025 17:10:16 +0000 Subject: [PATCH 07/17] repeat.test.js updated template --- Sprint-3/2-practice-tdd/repeat.js | 2 ++ Sprint-3/2-practice-tdd/repeat.test.js | 40 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/Sprint-3/2-practice-tdd/repeat.js b/Sprint-3/2-practice-tdd/repeat.js index 125840b92..6aea34899 100644 --- a/Sprint-3/2-practice-tdd/repeat.js +++ b/Sprint-3/2-practice-tdd/repeat.js @@ -1,3 +1,5 @@ +const repeat = require("./repeat"); + function repeat() { return "hellohellohello"; } diff --git a/Sprint-3/2-practice-tdd/repeat.test.js b/Sprint-3/2-practice-tdd/repeat.test.js index 34097b09c..6bf18ed73 100644 --- a/Sprint-3/2-practice-tdd/repeat.test.js +++ b/Sprint-3/2-practice-tdd/repeat.test.js @@ -3,6 +3,14 @@ const repeat = require("./repeat"); // Given a target string str and a positive integer count, // When the repeat function is called with these inputs, // Then it should: +function repeat(str, count) { + if (count < 0) { + throw new Error("Count must be a non-negative integer"); + } + return str.repeat(count); +} + +module.exports = repeat; // case: repeat String: // Given a target string str and a positive integer count, @@ -30,3 +38,35 @@ test("should repeat the string count times", () => { // 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. +const repeat = require("./repeat"); + +// Case 1: Repeat string multiple times +test("should repeat the string count times", () => { + const str = "hello"; + const count = 3; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual("hellohellohello"); +}); + +// Case 2: Handle count of 1 +test("should return the original string when count is 1", () => { + const str = "world"; + const count = 1; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual("world"); +}); + +// Case 3: Handle count of 0 +test("should return an empty string when count is 0", () => { + const str = "test"; + const count = 0; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual(""); +}); + +// Case 4: Negative count +test("should throw an error when count is negative", () => { + const str = "oops"; + const count = -2; + expect(() => repeat(str, count)).toThrow("Count must be a non-negative integer"); +}); From 44ce5680649e9a12e69620cbf3836617cc547575 Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Sat, 8 Nov 2025 14:27:18 +0000 Subject: [PATCH 08/17] adjusted Pr template --- Sprint-3/2-practice-tdd/count.js | 1 + Sprint-3/3-stretch/card-validator.md | 61 ++++++++++++++++++++++++ Sprint-3/3-stretch/password-validator.js | 38 ++++++++++++++- 3 files changed, 99 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index d22559ff9..8d794c34a 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -19,3 +19,4 @@ describe('countChar()', () => { expect(countChar('!!!', '!')).toBe(5); }); }); +//this is the end. diff --git a/Sprint-3/3-stretch/card-validator.md b/Sprint-3/3-stretch/card-validator.md index e39c6ace6..96336b244 100644 --- a/Sprint-3/3-stretch/card-validator.md +++ b/Sprint-3/3-stretch/card-validator.md @@ -33,3 +33,64 @@ These are the requirements your project needs to fulfill: - Return a boolean from the function to indicate whether the credit card number is valid. Good luck! + +function validateCreditCard(number) { + // Convert input to a string so we can check characters easily + const numStr = String(number); + + // Rule 1: Must be 16 digits, all numbers + if (!/^\d{16}$/.test(numStr)) { + return false; + } + + // Rule 2: Must contain at least two different digits + const uniqueDigits = new Set(numStr); + if (uniqueDigits.size < 2) { + return false; + } + + // Rule 3: The last digit must be even + const lastDigit = parseInt(numStr[numStr.length - 1]); + if (lastDigit % 2 !== 0) { + return false; + } + + // Rule 4: The sum of all digits must be greater than 16 + const sum = numStr + .split("") + .map(Number) + .reduce((a, b) => a + b, 0); + + if (sum <= 16) { + return false; + } + + // If all checks pass, return true ✅ + return true; +} + +module.exports = validateCreditCard; + +const validateCreditCard = require("./validateCreditCard"); + +test("valid credit card numbers should return true", () => { + expect(validateCreditCard("9999777788880000")).toBe(true); + expect(validateCreditCard("6666666666661666")).toBe(true); +}); + +test("invalid cards with letters should return false", () => { + expect(validateCreditCard("a92332119c011112")).toBe(false); +}); + +test("invalid cards with all same digits should return false", () => { + expect(validateCreditCard("4444444444444444")).toBe(false); +}); + +test("invalid cards with sum less than 16 should return false", () => { + expect(validateCreditCard("1111111111111110")).toBe(false); +}); + +test("invalid cards with odd final digit should return false", () => { + expect(validateCreditCard("6666666666666661")).toBe(false); +}); + diff --git a/Sprint-3/3-stretch/password-validator.js b/Sprint-3/3-stretch/password-validator.js index b55d527db..dcef0bdf7 100644 --- a/Sprint-3/3-stretch/password-validator.js +++ b/Sprint-3/3-stretch/password-validator.js @@ -3,4 +3,40 @@ function passwordValidator(password) { } -module.exports = passwordValidator; \ No newline at end of file +module.exports = passwordValidator; +function validateCreditCard(number) { + // Convert input to a string so we can check characters easily + const numStr = String(number); + + // Rule 1: Must be 16 digits, all numbers + if (!/^\d{16}$/.test(numStr)) { + return false; + } + + // Rule 2: Must contain at least two different digits + const uniqueDigits = new Set(numStr); + if (uniqueDigits.size < 2) { + return false; + } + + // Rule 3: The last digit must be even + const lastDigit = parseInt(numStr[numStr.length - 1]); + if (lastDigit % 2 !== 0) { + return false; + } + + // Rule 4: The sum of all digits must be greater than 16 + const sum = numStr + .split("") + .map(Number) + .reduce((a, b) => a + b, 0); + + if (sum <= 16) { + return false; + } + + // If all checks pass, return true ✅ + return true; +} + +module.exports = validateCreditCard; From 8eaf08cc6cf9fe0d4e6f30d3e8363c5b1f8f9be3 Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Sat, 8 Nov 2025 14:30:07 +0000 Subject: [PATCH 09/17] Added comment --- Sprint-3/2-practice-tdd/count.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 8d794c34a..90689ddca 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -20,3 +20,4 @@ describe('countChar()', () => { }); }); //this is the end. +// Last line \ No newline at end of file From e7cad8726e99dba7700098c375bff450f1010d25 Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Wed, 12 Nov 2025 18:43:25 +0000 Subject: [PATCH 10/17] count.test.js passed all the tests --- Sprint-3/2-practice-tdd/count.js | 26 ++++++-------------------- Sprint-3/2-practice-tdd/count.test.js | 16 ++++------------ 2 files changed, 10 insertions(+), 32 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 90689ddca..c6b15ce1c 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,23 +1,9 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + let count = 0; + for (let char of stringOfCharacters) { + if (char === findCharacter) count++; + } + return count; } -module.exports = countChar; - -const countChar = require('../countChar'); - -describe('countChar()', () => { - test('always returns 5', () => { - expect(countChar('anything', 'a')).toBe(5); - }); - - test('still returns 5 with empty string', () => { - expect(countChar('', 'z')).toBe(5); - }); - - test('still returns 5 with special characters', () => { - expect(countChar('!!!', '!')).toBe(5); - }); -}); -//this is the end. -// Last line \ No newline at end of file +module.exports = countChar; \ No newline at end of file diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 1bf611fc3..4e130554e 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -1,15 +1,4 @@ // implement a function countChar that counts the number of times a character occurs in a string -const countChar = require("./count"); - -function countChar(stringOfCharacters, findCharacter) { - let count = 0; - for (let char of stringOfCharacters) { - if (char === findCharacter) count++; - } - return count; -} - -module.exports = countChar; // Given a string str and a single character char to search for, // When the countChar function is called with these inputs, @@ -20,6 +9,9 @@ module.exports = countChar; // And a character char that may occur multiple times with overlaps within str (e.g., 'a' in 'aaaaa'), // When the function is called with these inputs, // Then it should correctly count overlapping occurrences of char (e.g., 'a' appears five times in 'aaaaa'). + +const countChar = require('./count'); + test("should count multiple occurrences of a character", () => { const str = "aaaaa"; @@ -54,7 +46,7 @@ test("should return 0 when the input string is empty", () => { // Scenario: Special Characters // It should correctly count spaces and punctuation. test("should count special characters like spaces or punctuation", () => { - expect(countChar("a b a b", " ")).toEqual(2); + expect(countChar("a b a b", " ")).toEqual(3); expect(countChar("wow!!!", "!")).toEqual(3); }); From 17a2043845d85ddb056cdd728ce9f46a107ff15b Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Wed, 12 Nov 2025 23:11:47 +0000 Subject: [PATCH 11/17] deleted repeat.js and adjusted repeat.str.test.js --- Sprint-3/2-practice-tdd/repeat-str.js | 8 ++- Sprint-3/2-practice-tdd/repeat-str.test.js | 64 ++-------------------- Sprint-3/2-practice-tdd/repeat.js | 11 ---- 3 files changed, 12 insertions(+), 71 deletions(-) delete mode 100644 Sprint-3/2-practice-tdd/repeat.js diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 3838c7b00..be93ad035 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,5 +1,9 @@ -function repeatStr() { - return "hellohellohello"; +function repeatStr(str, count) { + + if (count < 0) { + throw new Error("Count must be a non-negative integer"); + } + return str.repeat(count); } module.exports = repeatStr; diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index 8ff0812e8..211a4180a 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -1,72 +1,20 @@ -// Implement a function repeatStr -const repeatStr = require("./repeat-str"); -// Given a target string str and a positive integer count, -// When the repeatStr function is called with these inputs, -// Then it should: -function repeat(str, count) { - if (count < 0) { - throw new Error("Count must be a non-negative integer"); - } - return str.repeat(count); -} - -module.exports = repeat; - -// case: repeat String: -// Given a target string str and a positive integer count, -// When the repeatStr function is called with these inputs, -// Then it should repeat the str count times and return a new string containing the repeated str values. -test("should repeat the string count times", () => { - const str = "hello"; - const count = 3; - const repeatedStr = repeatStr(str, count); - expect(repeatedStr).toEqual("hellohellohello"); -}); -// 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, -// Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition. - -// 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, -// Then it should return an empty string, ensuring that a count of 0 results in an empty output. - -// case: 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 or return an appropriate error message, as negative counts are not valid. -const repeat = require("./repeat"); +const repeatStr = require("./repeat-str"); -// Case 1: Repeat string multiple times test("should repeat the string count times", () => { - const str = "hello"; - const count = 3; - const repeatedStr = repeat(str, count); - expect(repeatedStr).toEqual("hellohellohello"); + expect(repeatStr("hello", 3)).toBe("hellohellohello"); }); -// Case 2: Handle count of 1 test("should return the original string when count is 1", () => { - const str = "world"; - const count = 1; - const repeatedStr = repeat(str, count); - expect(repeatedStr).toEqual("world"); + expect(repeatStr("world", 1)).toBe("world"); }); -// Case 3: Handle count of 0 test("should return an empty string when count is 0", () => { - const str = "test"; - const count = 0; - const repeatedStr = repeat(str, count); - expect(repeatedStr).toEqual(""); + expect(repeatStr("test", 0)).toBe(""); }); -// Case 4: Negative count test("should throw an error when count is negative", () => { - const str = "oops"; - const count = -2; - expect(() => repeat(str, count)).toThrow("Count must be a non-negative integer"); + expect(() => repeatStr("oops", -2)).toThrow("Count must be a non-negative integer"); }); + diff --git a/Sprint-3/2-practice-tdd/repeat.js b/Sprint-3/2-practice-tdd/repeat.js deleted file mode 100644 index 6aea34899..000000000 --- a/Sprint-3/2-practice-tdd/repeat.js +++ /dev/null @@ -1,11 +0,0 @@ -const repeat = require("./repeat"); - -function repeat() { - return "hellohellohello"; -} - -module.exports = repeat; - -test("should repeat the given word three times", () => { - expect(repeat("hi", 3)).toBe("hihihi"); -}); From 4f483dde6f632a3b0c8e3148d3bca864174e87c0 Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Thu, 13 Nov 2025 14:57:10 +0000 Subject: [PATCH 12/17] modified PR --- Sprint-3/3-stretch/ validateCreditCard.js | 58 ++++++++++++++++++ Sprint-3/3-stretch/card-validator.md | 59 ------------------- Sprint-3/3-stretch/password-validator.js | 36 ----------- Sprint-3/3-stretch/validateCreditCard.test.js | 20 +++++++ 4 files changed, 78 insertions(+), 95 deletions(-) create mode 100644 Sprint-3/3-stretch/ validateCreditCard.js create mode 100644 Sprint-3/3-stretch/validateCreditCard.test.js diff --git a/Sprint-3/3-stretch/ validateCreditCard.js b/Sprint-3/3-stretch/ validateCreditCard.js new file mode 100644 index 000000000..7bacdecd8 --- /dev/null +++ b/Sprint-3/3-stretch/ validateCreditCard.js @@ -0,0 +1,58 @@ +function validateCreditCard(number) { + // Convert input to a string so we can check characters easily + const numStr = String(number); + + // Rule 1: Must be 16 digits, all numbers + if (!/^\d{16}$/.test(numStr)) { + return false; + } + + // Rule 2: Must contain at least two different digits + const uniqueDigits = new Set(numStr); + if (uniqueDigits.size < 2) { + return false; + } + + // Rule 3: The last digit must be even + const lastDigit = parseInt(numStr[numStr.length - 1]); + if (lastDigit % 2 !== 0) { + return false; + } + + // Rule 4: The sum of all digits must be greater than 16 + const sum = numStr + .split("") + .map(Number) + .reduce((a, b) => a + b, 0); + + if (sum <= 16) { + return false; + } + + // If all checks pass, return true ✅ + return true; +} + +module.exports = validateCreditCard; + + +test("valid credit card numbers should return true", () => { + expect(validateCreditCard("9999777788880000")).toBe(true); + expect(validateCreditCard("6666666666661666")).toBe(true); +}); + +test("invalid cards with letters should return false", () => { + expect(validateCreditCard("a92332119c011112")).toBe(false); +}); + +test("invalid cards with all same digits should return false", () => { + expect(validateCreditCard("4444444444444444")).toBe(false); +}); + +test("invalid cards with sum less than 16 should return false", () => { + expect(validateCreditCard("1111111111111110")).toBe(false); +}); + +test("invalid cards with odd final digit should return false", () => { + expect(validateCreditCard("6666666666666661")).toBe(false); +}); \ No newline at end of file diff --git a/Sprint-3/3-stretch/card-validator.md b/Sprint-3/3-stretch/card-validator.md index 96336b244..5e6451807 100644 --- a/Sprint-3/3-stretch/card-validator.md +++ b/Sprint-3/3-stretch/card-validator.md @@ -34,63 +34,4 @@ These are the requirements your project needs to fulfill: Good luck! -function validateCreditCard(number) { - // Convert input to a string so we can check characters easily - const numStr = String(number); - - // Rule 1: Must be 16 digits, all numbers - if (!/^\d{16}$/.test(numStr)) { - return false; - } - - // Rule 2: Must contain at least two different digits - const uniqueDigits = new Set(numStr); - if (uniqueDigits.size < 2) { - return false; - } - - // Rule 3: The last digit must be even - const lastDigit = parseInt(numStr[numStr.length - 1]); - if (lastDigit % 2 !== 0) { - return false; - } - - // Rule 4: The sum of all digits must be greater than 16 - const sum = numStr - .split("") - .map(Number) - .reduce((a, b) => a + b, 0); - - if (sum <= 16) { - return false; - } - - // If all checks pass, return true ✅ - return true; -} - -module.exports = validateCreditCard; - -const validateCreditCard = require("./validateCreditCard"); - -test("valid credit card numbers should return true", () => { - expect(validateCreditCard("9999777788880000")).toBe(true); - expect(validateCreditCard("6666666666661666")).toBe(true); -}); - -test("invalid cards with letters should return false", () => { - expect(validateCreditCard("a92332119c011112")).toBe(false); -}); - -test("invalid cards with all same digits should return false", () => { - expect(validateCreditCard("4444444444444444")).toBe(false); -}); - -test("invalid cards with sum less than 16 should return false", () => { - expect(validateCreditCard("1111111111111110")).toBe(false); -}); - -test("invalid cards with odd final digit should return false", () => { - expect(validateCreditCard("6666666666666661")).toBe(false); -}); diff --git a/Sprint-3/3-stretch/password-validator.js b/Sprint-3/3-stretch/password-validator.js index dcef0bdf7..12dd1accf 100644 --- a/Sprint-3/3-stretch/password-validator.js +++ b/Sprint-3/3-stretch/password-validator.js @@ -4,39 +4,3 @@ function passwordValidator(password) { module.exports = passwordValidator; -function validateCreditCard(number) { - // Convert input to a string so we can check characters easily - const numStr = String(number); - - // Rule 1: Must be 16 digits, all numbers - if (!/^\d{16}$/.test(numStr)) { - return false; - } - - // Rule 2: Must contain at least two different digits - const uniqueDigits = new Set(numStr); - if (uniqueDigits.size < 2) { - return false; - } - - // Rule 3: The last digit must be even - const lastDigit = parseInt(numStr[numStr.length - 1]); - if (lastDigit % 2 !== 0) { - return false; - } - - // Rule 4: The sum of all digits must be greater than 16 - const sum = numStr - .split("") - .map(Number) - .reduce((a, b) => a + b, 0); - - if (sum <= 16) { - return false; - } - - // If all checks pass, return true ✅ - return true; -} - -module.exports = validateCreditCard; diff --git a/Sprint-3/3-stretch/validateCreditCard.test.js b/Sprint-3/3-stretch/validateCreditCard.test.js new file mode 100644 index 000000000..a441994fe --- /dev/null +++ b/Sprint-3/3-stretch/validateCreditCard.test.js @@ -0,0 +1,20 @@ +test("valid credit card numbers should return true", () => { + expect(validateCreditCard("9999777788880000")).toBe(true); + expect(validateCreditCard("6666666666661666")).toBe(true); +}); + +test("invalid cards with letters should return false", () => { + expect(validateCreditCard("a92332119c011112")).toBe(false); +}); + +test("invalid cards with all same digits should return false", () => { + expect(validateCreditCard("4444444444444444")).toBe(false); +}); + +test("invalid cards with sum less than 16 should return false", () => { + expect(validateCreditCard("1111111111111110")).toBe(false); +}); + +test("invalid cards with odd final digit should return false", () => { + expect(validateCreditCard("6666666666666661")).toBe(false); +}); \ No newline at end of file From 9e313893ae20b10a6b9f12a079eba708e8d08e8e Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Sat, 15 Nov 2025 13:37:13 +0000 Subject: [PATCH 13/17] nothing changed --- Sprint-2/5-stretch-extend/format-time.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..2cfcba511 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -22,4 +22,4 @@ const targetOutput2 = "11:00 pm"; console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` -); +); \ No newline at end of file From f409459867749258cb823088ec338f5a28db25c2 Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Sat, 15 Nov 2025 13:42:21 +0000 Subject: [PATCH 14/17] restored 3-stretch from origin/main --- Sprint-3/3-stretch/ validateCreditCard.js | 58 ------------------- Sprint-3/3-stretch/card-validator.md | 2 - Sprint-3/3-stretch/password-validator.js | 2 +- Sprint-3/3-stretch/validateCreditCard.test.js | 20 ------- 4 files changed, 1 insertion(+), 81 deletions(-) delete mode 100644 Sprint-3/3-stretch/ validateCreditCard.js delete mode 100644 Sprint-3/3-stretch/validateCreditCard.test.js diff --git a/Sprint-3/3-stretch/ validateCreditCard.js b/Sprint-3/3-stretch/ validateCreditCard.js deleted file mode 100644 index 7bacdecd8..000000000 --- a/Sprint-3/3-stretch/ validateCreditCard.js +++ /dev/null @@ -1,58 +0,0 @@ -function validateCreditCard(number) { - // Convert input to a string so we can check characters easily - const numStr = String(number); - - // Rule 1: Must be 16 digits, all numbers - if (!/^\d{16}$/.test(numStr)) { - return false; - } - - // Rule 2: Must contain at least two different digits - const uniqueDigits = new Set(numStr); - if (uniqueDigits.size < 2) { - return false; - } - - // Rule 3: The last digit must be even - const lastDigit = parseInt(numStr[numStr.length - 1]); - if (lastDigit % 2 !== 0) { - return false; - } - - // Rule 4: The sum of all digits must be greater than 16 - const sum = numStr - .split("") - .map(Number) - .reduce((a, b) => a + b, 0); - - if (sum <= 16) { - return false; - } - - // If all checks pass, return true ✅ - return true; -} - -module.exports = validateCreditCard; - - -test("valid credit card numbers should return true", () => { - expect(validateCreditCard("9999777788880000")).toBe(true); - expect(validateCreditCard("6666666666661666")).toBe(true); -}); - -test("invalid cards with letters should return false", () => { - expect(validateCreditCard("a92332119c011112")).toBe(false); -}); - -test("invalid cards with all same digits should return false", () => { - expect(validateCreditCard("4444444444444444")).toBe(false); -}); - -test("invalid cards with sum less than 16 should return false", () => { - expect(validateCreditCard("1111111111111110")).toBe(false); -}); - -test("invalid cards with odd final digit should return false", () => { - expect(validateCreditCard("6666666666666661")).toBe(false); -}); \ No newline at end of file diff --git a/Sprint-3/3-stretch/card-validator.md b/Sprint-3/3-stretch/card-validator.md index 5e6451807..e39c6ace6 100644 --- a/Sprint-3/3-stretch/card-validator.md +++ b/Sprint-3/3-stretch/card-validator.md @@ -33,5 +33,3 @@ These are the requirements your project needs to fulfill: - Return a boolean from the function to indicate whether the credit card number is valid. Good luck! - - diff --git a/Sprint-3/3-stretch/password-validator.js b/Sprint-3/3-stretch/password-validator.js index 12dd1accf..b55d527db 100644 --- a/Sprint-3/3-stretch/password-validator.js +++ b/Sprint-3/3-stretch/password-validator.js @@ -3,4 +3,4 @@ function passwordValidator(password) { } -module.exports = passwordValidator; +module.exports = passwordValidator; \ No newline at end of file diff --git a/Sprint-3/3-stretch/validateCreditCard.test.js b/Sprint-3/3-stretch/validateCreditCard.test.js deleted file mode 100644 index a441994fe..000000000 --- a/Sprint-3/3-stretch/validateCreditCard.test.js +++ /dev/null @@ -1,20 +0,0 @@ -test("valid credit card numbers should return true", () => { - expect(validateCreditCard("9999777788880000")).toBe(true); - expect(validateCreditCard("6666666666661666")).toBe(true); -}); - -test("invalid cards with letters should return false", () => { - expect(validateCreditCard("a92332119c011112")).toBe(false); -}); - -test("invalid cards with all same digits should return false", () => { - expect(validateCreditCard("4444444444444444")).toBe(false); -}); - -test("invalid cards with sum less than 16 should return false", () => { - expect(validateCreditCard("1111111111111110")).toBe(false); -}); - -test("invalid cards with odd final digit should return false", () => { - expect(validateCreditCard("6666666666666661")).toBe(false); -}); \ No newline at end of file From 78dd2fd369b454fb09a70e81fdac8712330053a0 Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Sat, 15 Nov 2025 14:05:27 +0000 Subject: [PATCH 15/17] restored Sprint2 5-stretch-extend --- Sprint-2/5-stretch-extend/format-time.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 2cfcba511..32a32e66b 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -22,4 +22,4 @@ const targetOutput2 = "11:00 pm"; console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` -); \ No newline at end of file +); From 84090e8072bd7958cebc97a3ee1bba32a9801941 Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Sun, 16 Nov 2025 20:36:27 +0000 Subject: [PATCH 16/17] moved the test to the test.js file --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 37 ------------------ .../2-practice-tdd/get-ordinal-number.test.js | 39 ++++++++++++++++++- 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index 318f08619..4f4f5733e 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -22,40 +22,3 @@ function getOrdinalNumber(num) { module.exports = getOrdinalNumber; -const getOrdinalNumber = require("./getOrdinalNumber"); - -describe("getOrdinalNumber()", () => { - test("should return '1st' for 1", () => { - expect(getOrdinalNumber(1)).toBe("1st"); - }); - - test("should return '2nd' for 2", () => { - expect(getOrdinalNumber(2)).toBe("2nd"); - }); - - test("should return '3rd' for 3", () => { - expect(getOrdinalNumber(3)).toBe("3rd"); - }); - - test("should return '4th' for 4", () => { - expect(getOrdinalNumber(4)).toBe("4th"); - }); - - test("should return '11th', '12th', '13th' for special cases", () => { - expect(getOrdinalNumber(11)).toBe("11th"); - expect(getOrdinalNumber(12)).toBe("12th"); - expect(getOrdinalNumber(13)).toBe("13th"); - }); - - test("should return correct suffixes for 21, 22, 23", () => { - expect(getOrdinalNumber(21)).toBe("21st"); - expect(getOrdinalNumber(22)).toBe("22nd"); - expect(getOrdinalNumber(23)).toBe("23rd"); - }); - - test("should return '111th' for numbers ending with 11, 12, 13 even if larger", () => { - expect(getOrdinalNumber(111)).toBe("111th"); - expect(getOrdinalNumber(112)).toBe("112th"); - expect(getOrdinalNumber(113)).toBe("113th"); - }); -}); 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 b3d6419f7..63ec3bc11 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -15,6 +15,41 @@ module.exports = getOrdinalNumber; // When the number is 1, // Then the function should return "1st" -test("should return '1st' for 1", () => { - expect(getOrdinalNumber(1)).toEqual("1st"); + +const getOrdinalNumber = require("./getOrdinalNumber"); + +describe("getOrdinalNumber()", () => { + test("should return '1st' for 1", () => { + expect(getOrdinalNumber(1)).toBe("1st"); + }); + + test("should return '2nd' for 2", () => { + expect(getOrdinalNumber(2)).toBe("2nd"); + }); + + test("should return '3rd' for 3", () => { + expect(getOrdinalNumber(3)).toBe("3rd"); + }); + + test("should return '4th' for 4", () => { + expect(getOrdinalNumber(4)).toBe("4th"); + }); + + test("should return '11th', '12th', '13th' for special cases", () => { + expect(getOrdinalNumber(11)).toBe("11th"); + expect(getOrdinalNumber(12)).toBe("12th"); + expect(getOrdinalNumber(13)).toBe("13th"); + }); + + test("should return correct suffixes for 21, 22, 23", () => { + expect(getOrdinalNumber(21)).toBe("21st"); + expect(getOrdinalNumber(22)).toBe("22nd"); + expect(getOrdinalNumber(23)).toBe("23rd"); + }); + + test("should return '111th' for numbers ending with 11, 12, 13 even if larger", () => { + expect(getOrdinalNumber(111)).toBe("111th"); + expect(getOrdinalNumber(112)).toBe("112th"); + expect(getOrdinalNumber(113)).toBe("113th"); + }); }); From e0d530db50243e28f9bca83d523dcaedf86dbf61 Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Mon, 17 Nov 2025 11:39:38 +0000 Subject: [PATCH 17/17] made sure the tests all passed. --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 5 ----- 1 file changed, 5 deletions(-) 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 63ec3bc11..c2f963123 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -1,8 +1,5 @@ const getOrdinalNumber = require("./get-ordinal-number"); -function getOrdinalNumber(num) { - return "1st"; -} module.exports = getOrdinalNumber; @@ -16,8 +13,6 @@ module.exports = getOrdinalNumber; // Then the function should return "1st" -const getOrdinalNumber = require("./getOrdinalNumber"); - describe("getOrdinalNumber()", () => { test("should return '1st' for 1", () => { expect(getOrdinalNumber(1)).toBe("1st");