From 97ed99a95859e05cd41f3e77920ad527f63662fe Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Sun, 19 Jul 2026 23:18:33 +0200 Subject: [PATCH 01/14] add completed practice-tdd, dead-code, and stretch exercises --- Sprint-3/2-practice-tdd/count.js | 6 +++ Sprint-3/2-practice-tdd/count.test.js | 15 +++++++ Sprint-3/2-practice-tdd/get-ordinal-number.js | 10 +++++ .../2-practice-tdd/get-ordinal-number.test.js | 14 +++++- Sprint-3/3-dead-code/exercise-1.js | 3 +- Sprint-3/3-dead-code/exercise-2.js | 6 +-- Sprint-3/4-stretch/find.js | 18 ++++++++ Sprint-3/4-stretch/password-validator.js | 9 ++++ Sprint-3/4-stretch/password-validator.test.js | 45 ++++++++++++++++++- 9 files changed, 118 insertions(+), 8 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..719fddbefa 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -3,3 +3,9 @@ function countChar(stringOfCharacters, findCharacter) { } module.exports = countChar; + test( "should count multiple occurrences of a character ", function(){ + const stringofcharacters = "aaaaa"; + const findcharcaters = "a"; + const count = countChar(stringofcharacters, findcharcaters); + expect(count).toEqual(5); + }); \ 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 179ea0ddf7..7c494f3337 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -3,6 +3,15 @@ const countChar = require("./count"); // Given a string `str` and a single character `char` to search for, // When the countChar function is called with these inputs, // Then it should: +function CountChar(str, char) { + let count = 0; + for (let i = 0; i < str.length; i++) { + if (str[i] === char) { + count++; + } + } + return count; +} // Scenario: Multiple Occurrences // Given the input string `str`, @@ -22,3 +31,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 the character does not occur in the string', () => { + const str = "hello"; + const char = "x"; + const count = countChar(str, char); + expect(count).toEqual(5); +}); \ No newline at end of file diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db13..e56ce47b94 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -3,3 +3,13 @@ function getOrdinalNumber(num) { } module.exports = getOrdinalNumber; + test(`works with any number ending with 1, except for 11. For all other numbers, it should return the number followed by "th" with exceptions to 2 and 3 `, () => { + expect(getOrdinalNumber(1)).toBe("1st"); + expect(getOrdinalNumber(2)).toBe("2nd"); + expect(getOrdinalNumber(3)).toBe("3rd"); + expect(getOrdinalNumber(4)).toBe("4th"); + expect(getOrdinalNumber(11)).toBe("11th"); + expect(getOrdinalNumber(12)).toBe("12th"); + }); + + \ No newline at end of file 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..1df44e4458 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,18 @@ const getOrdinalNumber = require("./get-ordinal-number"); // Then the function should return a string by appending "st" to the number. test("should append 'st' for numbers ending with 1, except those ending with 11", () => { expect(getOrdinalNumber(1)).toEqual("1st"); - expect(getOrdinalNumber(21)).toEqual("21st"); + expect(getOrdinalNumber(31)).toEqual("31st"); expect(getOrdinalNumber(131)).toEqual("131st"); }); + 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"); +}); + + test(`should append 'rd' for numbers ending with 3 except those ending with 13 `, () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(23)).toEqual("23rd"); + expect(getOrdinalNumber(143)).toEqual("143rd"); +}); + \ No newline at end of file diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js index 4d09f15fa9..a68f274f26 100644 --- a/Sprint-3/3-dead-code/exercise-1.js +++ b/Sprint-3/3-dead-code/exercise-1.js @@ -5,9 +5,8 @@ let testName = "Jerry"; const greeting = "hello"; function sayHello(greeting, name) { - const greetingStr = greeting + ", " + name + "!"; return `${greeting}, ${name}!`; - console.log(greetingStr); + } testName = "Aman"; diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js index 56d7887c4c..d865830a2e 100644 --- a/Sprint-3/3-dead-code/exercise-2.js +++ b/Sprint-3/3-dead-code/exercise-2.js @@ -2,12 +2,10 @@ // The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable. const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; -const capitalisedPets = pets.map((pet) => pet.toUpperCase()); + const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); -function logPets(petsArr) { - petsArr.forEach((pet) => console.log(pet)); -} + function countAndCapitalisePets(petsArr) { const petCount = {}; diff --git a/Sprint-3/4-stretch/find.js b/Sprint-3/4-stretch/find.js index c7e79a2f21..6ab0d27c9b 100644 --- a/Sprint-3/4-stretch/find.js +++ b/Sprint-3/4-stretch/find.js @@ -20,6 +20,24 @@ console.log(find("code your future", "z")); // Pay particular attention to the following: // a) How the index variable updates during the call to find +// the index variable starts at 0 and is incremented by 1 after each iteration of the while loop. + // b) What is the if statement used to check +// the if statement is used to check if the character at the current index of the string is equal to the character we are searching for. +// if the condition is true ,it will return the index of the character in the string. ' +// if the condition is false, it will continue to the next iteration of the loop until it finds the character or reaches the end of the string. + // c) Why is index++ being used? +/* + the index++ is used to increment the index variable by 1 after each iteration of the loop. +This allows the loop to move to the next character in the string for the next iteration. Without this increment, +the loop would get stuck on the same character and could potentially run indefinitely if the condition is never met. +*/ + // d) What is the condition index < str.length used for? +/* +the index < str.length condition is used to ensure that the loop continues to iterate through the string until it reaches the end. +the index variable is used to keep track of the current position in the string, and the loop will continue as long as index is less than the length of the string. +Once index reaches the length of the string, + it means we have checked all characters in the string, and if we haven't found the character we're looking for, we return -1 to indicate that it was not found. + */ \ No newline at end of file diff --git a/Sprint-3/4-stretch/password-validator.js b/Sprint-3/4-stretch/password-validator.js index b55d527dba..615e3d0b8c 100644 --- a/Sprint-3/4-stretch/password-validator.js +++ b/Sprint-3/4-stretch/password-validator.js @@ -3,4 +3,13 @@ function passwordValidator(password) { } +module.exports = passwordValidator; + function passwordValidator(password) { + if (password.length < 5){ + return false; + } else if (password.length >= 5 ){ + return true; + } +} + module.exports = passwordValidator; \ No newline at end of file diff --git a/Sprint-3/4-stretch/password-validator.test.js b/Sprint-3/4-stretch/password-validator.test.js index 8fa3089d6b..eb230a67a1 100644 --- a/Sprint-3/4-stretch/password-validator.test.js +++ b/Sprint-3/4-stretch/password-validator.test.js @@ -23,4 +23,47 @@ test("password has at least 5 characters", () => { // Assert expect(result).toEqual(true); } -); \ No newline at end of file +); +// instruction 2 +const isValidPassword = require("./password-validator"); +test("password has least one uppercase letter", () => { + // arrange + const uppercase = "A -Z"; + // act + const result = isValidPassword(uppercase); + // assert + expect(result).toEqual(true); +}); + +// instruction 3 +const isValidPassword = require("./password-validator"); +test("password has least one lowercase letter", () => { + // arrange + const lowercase = "a-z"; + // act + const result = isValidPassword(lowercase); + // assert + expect(result).toEqual(true); +}); + +// instruction 4 +const isValidPassword = require("./password-validator"); +test("password has least one number", () => { + // arrange + const number = "0-9"; + // act + const result = isValidPassword(number); + // assert + expect(result).toEqual(true); +}); + +// instruction 5 +const isValidPassword = require("./password-validator"); +test("password has least one non-alphanumeric symbol", () => { + // arrange + const symbol = "!#$%.*&"; + // act + const result = isValidPassword(symbol); + // assert + expect(result).toEqual(true); +}); \ No newline at end of file From eb034f33be1c12a996e1afaa2a14dd34f8b288d1 Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Sun, 19 Jul 2026 23:39:52 +0200 Subject: [PATCH 02/14] remove dead-code and stretch files, not part of this task --- Sprint-3/3-dead-code/exercise-1.js | 3 +- Sprint-3/3-dead-code/exercise-2.js | 6 ++- Sprint-3/4-stretch/find.js | 18 -------- Sprint-3/4-stretch/password-validator.js | 9 ---- Sprint-3/4-stretch/password-validator.test.js | 45 +------------------ 5 files changed, 7 insertions(+), 74 deletions(-) diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js index a68f274f26..4d09f15fa9 100644 --- a/Sprint-3/3-dead-code/exercise-1.js +++ b/Sprint-3/3-dead-code/exercise-1.js @@ -5,8 +5,9 @@ let testName = "Jerry"; const greeting = "hello"; function sayHello(greeting, name) { + const greetingStr = greeting + ", " + name + "!"; return `${greeting}, ${name}!`; - + console.log(greetingStr); } testName = "Aman"; diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js index d865830a2e..56d7887c4c 100644 --- a/Sprint-3/3-dead-code/exercise-2.js +++ b/Sprint-3/3-dead-code/exercise-2.js @@ -2,10 +2,12 @@ // The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable. const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; - +const capitalisedPets = pets.map((pet) => pet.toUpperCase()); const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); - +function logPets(petsArr) { + petsArr.forEach((pet) => console.log(pet)); +} function countAndCapitalisePets(petsArr) { const petCount = {}; diff --git a/Sprint-3/4-stretch/find.js b/Sprint-3/4-stretch/find.js index 6ab0d27c9b..c7e79a2f21 100644 --- a/Sprint-3/4-stretch/find.js +++ b/Sprint-3/4-stretch/find.js @@ -20,24 +20,6 @@ console.log(find("code your future", "z")); // Pay particular attention to the following: // a) How the index variable updates during the call to find -// the index variable starts at 0 and is incremented by 1 after each iteration of the while loop. - // b) What is the if statement used to check -// the if statement is used to check if the character at the current index of the string is equal to the character we are searching for. -// if the condition is true ,it will return the index of the character in the string. ' -// if the condition is false, it will continue to the next iteration of the loop until it finds the character or reaches the end of the string. - // c) Why is index++ being used? -/* - the index++ is used to increment the index variable by 1 after each iteration of the loop. -This allows the loop to move to the next character in the string for the next iteration. Without this increment, -the loop would get stuck on the same character and could potentially run indefinitely if the condition is never met. -*/ - // d) What is the condition index < str.length used for? -/* -the index < str.length condition is used to ensure that the loop continues to iterate through the string until it reaches the end. -the index variable is used to keep track of the current position in the string, and the loop will continue as long as index is less than the length of the string. -Once index reaches the length of the string, - it means we have checked all characters in the string, and if we haven't found the character we're looking for, we return -1 to indicate that it was not found. - */ \ No newline at end of file diff --git a/Sprint-3/4-stretch/password-validator.js b/Sprint-3/4-stretch/password-validator.js index 615e3d0b8c..b55d527dba 100644 --- a/Sprint-3/4-stretch/password-validator.js +++ b/Sprint-3/4-stretch/password-validator.js @@ -3,13 +3,4 @@ function passwordValidator(password) { } -module.exports = passwordValidator; - function passwordValidator(password) { - if (password.length < 5){ - return false; - } else if (password.length >= 5 ){ - return true; - } -} - module.exports = passwordValidator; \ No newline at end of file diff --git a/Sprint-3/4-stretch/password-validator.test.js b/Sprint-3/4-stretch/password-validator.test.js index eb230a67a1..8fa3089d6b 100644 --- a/Sprint-3/4-stretch/password-validator.test.js +++ b/Sprint-3/4-stretch/password-validator.test.js @@ -23,47 +23,4 @@ test("password has at least 5 characters", () => { // Assert expect(result).toEqual(true); } -); -// instruction 2 -const isValidPassword = require("./password-validator"); -test("password has least one uppercase letter", () => { - // arrange - const uppercase = "A -Z"; - // act - const result = isValidPassword(uppercase); - // assert - expect(result).toEqual(true); -}); - -// instruction 3 -const isValidPassword = require("./password-validator"); -test("password has least one lowercase letter", () => { - // arrange - const lowercase = "a-z"; - // act - const result = isValidPassword(lowercase); - // assert - expect(result).toEqual(true); -}); - -// instruction 4 -const isValidPassword = require("./password-validator"); -test("password has least one number", () => { - // arrange - const number = "0-9"; - // act - const result = isValidPassword(number); - // assert - expect(result).toEqual(true); -}); - -// instruction 5 -const isValidPassword = require("./password-validator"); -test("password has least one non-alphanumeric symbol", () => { - // arrange - const symbol = "!#$%.*&"; - // act - const result = isValidPassword(symbol); - // assert - expect(result).toEqual(true); -}); \ No newline at end of file +); \ No newline at end of file From ac7995320e28435829a68ffafe833ce5463af47e Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Thu, 13 Aug 2026 00:18:19 +0200 Subject: [PATCH 03/14] Add get-ordinal-number fix --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index e56ce47b94..84477bbe98 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,15 +1,20 @@ function getOrdinalNumber(num) { - return "1st"; -} + const lastTwoDigits = num % 100; + const lastDigit = num % 10; + + if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { + return `${num}th`; + } -module.exports = getOrdinalNumber; - test(`works with any number ending with 1, except for 11. For all other numbers, it should return the number followed by "th" with exceptions to 2 and 3 `, () => { - expect(getOrdinalNumber(1)).toBe("1st"); - expect(getOrdinalNumber(2)).toBe("2nd"); - expect(getOrdinalNumber(3)).toBe("3rd"); - expect(getOrdinalNumber(4)).toBe("4th"); - expect(getOrdinalNumber(11)).toBe("11th"); - expect(getOrdinalNumber(12)).toBe("12th"); - }); + if (lastDigit === 1) { + return `${num}st`; + } else if (lastDigit === 2) { + return `${num}nd`; + } else if (lastDigit === 3) { + return `${num}rd`; + } else { + return `${num}th`; + } +} - \ No newline at end of file +module.exports = getOrdinalNumber; \ No newline at end of file From 01bb3dfc0dd4b8c647ea0474efdf6634ec0ce8df Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Thu, 13 Aug 2026 12:14:06 +0200 Subject: [PATCH 04/14] Fix countChar implementation and resolve test conflicts --- Sprint-3/2-practice-tdd/count.js | 10 ++-------- Sprint-3/2-practice-tdd/count.test.js | 19 +++++-------------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 719fddbefa..17e1f035b7 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,11 +1,5 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + return stringOfCharacters.split("").filter(char => char === findCharacter).length; } -module.exports = countChar; - test( "should count multiple occurrences of a character ", function(){ - const stringofcharacters = "aaaaa"; - const findcharcaters = "a"; - const count = countChar(stringofcharacters, findcharcaters); - expect(count).toEqual(5); - }); \ 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 7c494f3337..f8256d93ed 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -1,24 +1,15 @@ // implement a function countChar that counts the number of times a character occurs in a string +// implement a function countChar that counts the number of times a character occurs in a string const countChar = require("./count"); // Given a string `str` and a single character `char` to search for, // When the countChar function is called with these inputs, // Then it should: -function CountChar(str, char) { - let count = 0; - for (let i = 0; i < str.length; i++) { - if (str[i] === char) { - count++; - } - } - return count; -} // Scenario: Multiple Occurrences // Given the input string `str`, // And a character `char` that occurs one or more times in `str` (e.g., 'a' in 'aaaaa'), // When the function is called with these inputs, // Then it should correctly count occurrences of `char`. - test("should count multiple occurrences of a character", () => { const str = "aaaaa"; const char = "a"; @@ -31,9 +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 the character does not occur in the string', () => { - const str = "hello"; - const char = "x"; +test("should return 0 when the character does not occur", () => { + const str = "aaaaa"; + const char = "b"; const count = countChar(str, char); - expect(count).toEqual(5); + expect(count).toEqual(0); }); \ No newline at end of file From 95a30fef291bee19d8ed86cc9b1d02d52bb97d98 Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Tue, 18 Aug 2026 21:22:28 +0200 Subject: [PATCH 05/14] modified --- .../implement/1-get-angle-type.js | 39 +++++++++--------- .../implement/2-is-proper-fraction.js | 23 +++-------- .../implement/3-get-card-value.js | 40 ++++++++----------- 3 files changed, 42 insertions(+), 60 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index 9e05a871e2..426166d272 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -15,23 +15,26 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - // TODO: Implement this function -} + if (angle > 0 && angle < 90) { + return "Acute angle"; + } -// The line below allows us to load the getAngleType function into tests in other files. -// This will be useful in the "rewrite tests with jest" step. -module.exports = getAngleType; - -// This helper function is written to make our assertions easier to read. -// If the actual output matches the target output, the test will pass -function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); -} + if (angle === 90) { + return "Right angle"; + } + + if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } -// TODO: Write tests to cover all cases, including boundary and invalid cases. -// Example: Identify Right Angles -const right = getAngleType(90); -assertEquals(right, "Right angle"); + if (angle === 180) { + return "Straight angle"; + } + + if (angle > 180 && angle < 360) { + return "Reflex angle"; + } + + return "Invalid angle"; +} +module.exports = getAngleType; \ No newline at end of file diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index 970cb9b641..2e7f9909a9 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -9,25 +9,12 @@ // Acceptance criteria: // After you have implemented the function, write tests to cover all the cases, and // execute the code to ensure all tests pass. - function isProperFraction(numerator, denominator) { - // TODO: Implement this function -} + if (denominator === 0) { + return false; + } -// The line below allows us to load the isProperFraction function into tests in other files. -// This will be useful in the "rewrite tests with jest" step. -module.exports = isProperFraction; - -// Here's our helper again -function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); + return Math.abs(numerator) < Math.abs(denominator); } -// TODO: Write tests to cover all cases. -// What combinations of numerators and denominators should you test? - -// Example: 1/2 is a proper fraction -assertEquals(isProperFraction(1, 2), true); +module.exports = isProperFraction; \ No newline at end of file diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index ff5c532e1d..9ff25d68c0 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -20,35 +20,27 @@ // Acceptance criteria: // After you have implemented the function, write tests to cover all the cases, and // execute the code to ensure all tests pass. - function getCardValue(card) { - // TODO: Implement this function -} + const rank = card.slice(0, -1); + const suit = card.slice(-1); -// The line below allows us to load the getCardValue function into tests in other files. -// This will be useful in the "rewrite tests with jest" step. -module.exports = getCardValue; + const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]; -// Helper functions to make our assertions easier to read. -function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); -} + const validSuits = ["♠", "♥", "♦", "♣"]; + + if (!validRanks.includes(rank) || !validSuits.includes(suit)) { + throw new Error("Invalid card"); + } -// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. -// Examples: -assertEquals(getCardValue("9♠"), 9); + if (rank === "A") { + return 11; + } -// Handling invalid cards -try { - getCardValue("invalid"); + if (["J", "Q", "K"].includes(rank)) { + return 10; + } - // This line will not be reached if an error is thrown as expected - console.error("Error was not thrown for invalid card 😢"); -} catch (e) { - console.log("Error thrown for invalid card 🎉"); + return Number(rank); } -// What other invalid card cases can you think of? +module.exports = getCardValue; From d36862ab4dee9d806ee7589703d66cc014415525 Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Tue, 18 Aug 2026 21:37:24 +0200 Subject: [PATCH 06/14] Remove unrelated get angle type changes --- .../implement/1-get-angle-type.js | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index 426166d272..9e05a871e2 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -15,26 +15,23 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - if (angle > 0 && angle < 90) { - return "Acute angle"; - } - - if (angle === 90) { - return "Right angle"; - } - - if (angle > 90 && angle < 180) { - return "Obtuse angle"; - } - - if (angle === 180) { - return "Straight angle"; - } - - if (angle > 180 && angle < 360) { - return "Reflex angle"; - } + // TODO: Implement this function +} - return "Invalid angle"; +// The line below allows us to load the getAngleType function into tests in other files. +// This will be useful in the "rewrite tests with jest" step. +module.exports = getAngleType; + +// This helper function is written to make our assertions easier to read. +// If the actual output matches the target output, the test will pass +function assertEquals(actualOutput, targetOutput) { + console.assert( + actualOutput === targetOutput, + `Expected ${actualOutput} to equal ${targetOutput}` + ); } -module.exports = getAngleType; \ No newline at end of file + +// TODO: Write tests to cover all cases, including boundary and invalid cases. +// Example: Identify Right Angles +const right = getAngleType(90); +assertEquals(right, "Right angle"); From 33639ec111e0beede5b5805d0482c99a0a87c1a0 Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Tue, 18 Aug 2026 23:58:03 +0200 Subject: [PATCH 07/14] Fix getOrdinalNumber suffix logic --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index 84477bbe98..2ea38415b3 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,3 +1,4 @@ +<<<<<<< Updated upstream function getOrdinalNumber(num) { const lastTwoDigits = num % 100; const lastDigit = num % 10; @@ -14,6 +15,24 @@ function getOrdinalNumber(num) { return `${num}rd`; } else { return `${num}th`; +======= +function getOrdinalNumber(number) { + const lastDigit = number % 10; + const lastTwoDigits = number % 100; + + if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { + return number + "th"; + } + + if (lastDigit === 1) { + return number + "st"; + } else if (lastDigit === 2) { + return number + "nd"; + } else if (lastDigit === 3) { + return number + "rd"; + } else { + return number + "th"; +>>>>>>> Stashed changes } } From 7cd35563d6a7eb3c998a79a8fed104aa5dd6fc75 Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Wed, 19 Aug 2026 00:06:56 +0200 Subject: [PATCH 08/14] Implement getAngleType and fix getOrdinalNumber --- .../implement/1-get-angle-type.js | 34 +++++++------------ Sprint-3/2-practice-tdd/get-ordinal-number.js | 19 ----------- 2 files changed, 13 insertions(+), 40 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index 9e05a871e2..c8ebef2b4b 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -7,31 +7,23 @@ // - "Straight angle" for exactly 180° // - "Reflex angle" for angles greater than 180° and less than 360° // - "Invalid angle" for angles outside the valid range. - // Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.) -// Acceptance criteria: -// After you have implemented the function, write tests to cover all the cases, and -// execute the code to ensure all tests pass. - function getAngleType(angle) { - // TODO: Implement this function + if (angle > 0 && angle < 90) { + return "Acute angle"; + } else if (angle === 90) { + return "Right angle"; + } else if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } else if (angle === 180) { + return "Straight angle"; + } else if (angle > 180 && angle < 360) { + return "Reflex angle"; + } else { + return "Invalid angle"; + } } // The line below allows us to load the getAngleType function into tests in other files. -// This will be useful in the "rewrite tests with jest" step. module.exports = getAngleType; - -// This helper function is written to make our assertions easier to read. -// If the actual output matches the target output, the test will pass -function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); -} - -// TODO: Write tests to cover all cases, including boundary and invalid cases. -// Example: Identify Right Angles -const right = getAngleType(90); -assertEquals(right, "Right angle"); diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index 2ea38415b3..84477bbe98 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,4 +1,3 @@ -<<<<<<< Updated upstream function getOrdinalNumber(num) { const lastTwoDigits = num % 100; const lastDigit = num % 10; @@ -15,24 +14,6 @@ function getOrdinalNumber(num) { return `${num}rd`; } else { return `${num}th`; -======= -function getOrdinalNumber(number) { - const lastDigit = number % 10; - const lastTwoDigits = number % 100; - - if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { - return number + "th"; - } - - if (lastDigit === 1) { - return number + "st"; - } else if (lastDigit === 2) { - return number + "nd"; - } else if (lastDigit === 3) { - return number + "rd"; - } else { - return number + "th"; ->>>>>>> Stashed changes } } From 1a326b8d9b3eee1d9072bc6fb3a1274696b0dfff Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Wed, 19 Aug 2026 00:16:59 +0200 Subject: [PATCH 09/14] Remove unrelated file changes not part of practice-tdd task --- .../implement/2-is-proper-fraction.js | 23 ++++++++--- .../implement/3-get-card-value.js | 40 +++++++++++-------- 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index 2e7f9909a9..970cb9b641 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -9,12 +9,25 @@ // Acceptance criteria: // After you have implemented the function, write tests to cover all the cases, and // execute the code to ensure all tests pass. + function isProperFraction(numerator, denominator) { - if (denominator === 0) { - return false; - } + // TODO: Implement this function +} - return Math.abs(numerator) < Math.abs(denominator); +// The line below allows us to load the isProperFraction function into tests in other files. +// This will be useful in the "rewrite tests with jest" step. +module.exports = isProperFraction; + +// Here's our helper again +function assertEquals(actualOutput, targetOutput) { + console.assert( + actualOutput === targetOutput, + `Expected ${actualOutput} to equal ${targetOutput}` + ); } -module.exports = isProperFraction; \ No newline at end of file +// TODO: Write tests to cover all cases. +// What combinations of numerators and denominators should you test? + +// Example: 1/2 is a proper fraction +assertEquals(isProperFraction(1, 2), true); diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index 9ff25d68c0..ff5c532e1d 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -20,27 +20,35 @@ // Acceptance criteria: // After you have implemented the function, write tests to cover all the cases, and // execute the code to ensure all tests pass. -function getCardValue(card) { - const rank = card.slice(0, -1); - const suit = card.slice(-1); - const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]; +function getCardValue(card) { + // TODO: Implement this function +} - const validSuits = ["♠", "♥", "♦", "♣"]; +// The line below allows us to load the getCardValue function into tests in other files. +// This will be useful in the "rewrite tests with jest" step. +module.exports = getCardValue; - if (!validRanks.includes(rank) || !validSuits.includes(suit)) { - throw new Error("Invalid card"); - } +// Helper functions to make our assertions easier to read. +function assertEquals(actualOutput, targetOutput) { + console.assert( + actualOutput === targetOutput, + `Expected ${actualOutput} to equal ${targetOutput}` + ); +} - if (rank === "A") { - return 11; - } +// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. +// Examples: +assertEquals(getCardValue("9♠"), 9); - if (["J", "Q", "K"].includes(rank)) { - return 10; - } +// Handling invalid cards +try { + getCardValue("invalid"); - return Number(rank); + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); } -module.exports = getCardValue; +// What other invalid card cases can you think of? From 0e5b084cb08677b967cdfec25ccf455f8073c4c4 Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Wed, 19 Aug 2026 00:23:51 +0200 Subject: [PATCH 10/14] Remove unrelated get-angle-type changes from practice-tdd branch --- .../implement/1-get-angle-type.js | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index c8ebef2b4b..9e05a871e2 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -7,23 +7,31 @@ // - "Straight angle" for exactly 180° // - "Reflex angle" for angles greater than 180° and less than 360° // - "Invalid angle" for angles outside the valid range. + // Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.) +// Acceptance criteria: +// After you have implemented the function, write tests to cover all the cases, and +// execute the code to ensure all tests pass. + function getAngleType(angle) { - if (angle > 0 && angle < 90) { - return "Acute angle"; - } else if (angle === 90) { - return "Right angle"; - } else if (angle > 90 && angle < 180) { - return "Obtuse angle"; - } else if (angle === 180) { - return "Straight angle"; - } else if (angle > 180 && angle < 360) { - return "Reflex angle"; - } else { - return "Invalid angle"; - } + // TODO: Implement this function } // The line below allows us to load the getAngleType function into tests in other files. +// This will be useful in the "rewrite tests with jest" step. module.exports = getAngleType; + +// This helper function is written to make our assertions easier to read. +// If the actual output matches the target output, the test will pass +function assertEquals(actualOutput, targetOutput) { + console.assert( + actualOutput === targetOutput, + `Expected ${actualOutput} to equal ${targetOutput}` + ); +} + +// TODO: Write tests to cover all cases, including boundary and invalid cases. +// Example: Identify Right Angles +const right = getAngleType(90); +assertEquals(right, "Right angle"); From 3cdc069ba2507700366c085714fce650d0b0d96a Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Wed, 19 Aug 2026 00:32:18 +0200 Subject: [PATCH 11/14] added other numbers to the tests --- Project-CLI-Treasure-Hunt | 1 + .../2-practice-tdd/get-ordinal-number.test.js | 35 +++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) create mode 160000 Project-CLI-Treasure-Hunt diff --git a/Project-CLI-Treasure-Hunt b/Project-CLI-Treasure-Hunt new file mode 160000 index 0000000000..3e66462a26 --- /dev/null +++ b/Project-CLI-Treasure-Hunt @@ -0,0 +1 @@ +Subproject commit 3e66462a26c1d68cc2ac562b0d3ad7b3c2210fa1 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 1df44e4458..08168834b2 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -9,24 +9,29 @@ const getOrdinalNumber = require("./get-ordinal-number"); // Instead of writing tests for individual numbers, consider grouping all possible input values // into meaningful categories. Then, select representative samples from each category to test. // This approach improves coverage and makes our tests easier to maintain. +// Case 4: Numbers ending with 11, 12, or 13 (the exceptions) +// These should always get "th", even though they end in 1, 2, or 3. + // Case 1: Numbers ending with 1 (but not 11) // When the number ends with 1, except those ending with 11, // Then the function should return a string by appending "st" to the number. -test("should append 'st' for numbers ending with 1, except those ending with 11", () => { - expect(getOrdinalNumber(1)).toEqual("1st"); - expect(getOrdinalNumber(31)).toEqual("31st"); - expect(getOrdinalNumber(131)).toEqual("131st"); -}); - 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 11, 12, or 13 (the exceptions) +// These should always get "th", even though they end in 1, 2, or 3. +test("should append 'th' for numbers ending with 11, 12, or 13", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); + expect(getOrdinalNumber(111)).toEqual("111th"); + expect(getOrdinalNumber(112)).toEqual("112th"); + expect(getOrdinalNumber(113)).toEqual("113th"); }); - test(`should append 'rd' for numbers ending with 3 except those ending with 13 `, () => { - expect(getOrdinalNumber(3)).toEqual("3rd"); - expect(getOrdinalNumber(23)).toEqual("23rd"); - expect(getOrdinalNumber(143)).toEqual("143rd"); -}); - \ No newline at end of file +// Case 5: Numbers ending with 4-9, and 0 +// These should always get "th". +test("should append 'th' for numbers ending with 0 or 4-9", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(15)).toEqual("15th"); + expect(getOrdinalNumber(20)).toEqual("20th"); + expect(getOrdinalNumber(100)).toEqual("100th"); +}); \ No newline at end of file From e9eb5e8615c6943dd2650506b748216984aae817 Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Wed, 19 Aug 2026 00:37:08 +0200 Subject: [PATCH 12/14] Remove accidentally committed Project-CLI-Treasure-Hunt subproject --- .gitignore | 2 +- Project-CLI-Treasure-Hunt | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 160000 Project-CLI-Treasure-Hunt diff --git a/.gitignore b/.gitignore index bde36e5302..1098fad227 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ node_modules .DS_Store .vscode -**/.DS_Store \ No newline at end of file +**/.DS_StoreProject-CLI-Treasure-Hunt/ diff --git a/Project-CLI-Treasure-Hunt b/Project-CLI-Treasure-Hunt deleted file mode 160000 index 3e66462a26..0000000000 --- a/Project-CLI-Treasure-Hunt +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3e66462a26c1d68cc2ac562b0d3ad7b3c2210fa1 From 00b0c7a41e653b196dc6d8b09fdbe9d017786323 Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Wed, 19 Aug 2026 00:40:50 +0200 Subject: [PATCH 13/14] Remove .gitignore addition not part of this task --- .gitignore | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 1098fad227..0000000000 --- a/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -node_modules -.DS_Store -.vscode -**/.DS_StoreProject-CLI-Treasure-Hunt/ From b1470ba9e87413216fd49f249699458acac45ce5 Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Wed, 19 Aug 2026 00:48:11 +0200 Subject: [PATCH 14/14] Restore .gitignore to match main --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..bde36e5302 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules +.DS_Store +.vscode +**/.DS_Store \ No newline at end of file