From 2dc31c33dc1bfbe1f6988fda082c42b8c90dc47a Mon Sep 17 00:00:00 2001 From: Alrzini2025 Date: Wed, 25 Feb 2026 11:00:05 +0000 Subject: [PATCH 01/11] I have dome sprint2 for structuring data module --- Sprint-1/1-key-exercises/1-count.js | 1 + Sprint-2/1-key-errors/0.js | 14 ++++----- Sprint-2/1-key-errors/1.js | 13 +++----- Sprint-2/1-key-errors/2.js | 23 +++++++++----- Sprint-2/2-mandatory-debug/0.js | 22 ++++++++++++- Sprint-2/2-mandatory-debug/1.js | 20 ++++++++++++ Sprint-2/2-mandatory-debug/2.js | 31 +++++++++++++++++++ Sprint-2/3-mandatory-implement/1-bmi.js | 5 ++- Sprint-2/3-mandatory-implement/2-cases.js | 16 ++++++++++ Sprint-2/3-mandatory-implement/3-to-pounds.js | 29 +++++++++++++++++ Sprint-2/4-mandatory-interpret/time-format.js | 6 ++++ Sprint-2/5-stretch-extend/format-time.js | 24 ++++++++++++++ 12 files changed, 179 insertions(+), 25 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..20ac1f4e7 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,4 @@ count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing +// updates the value of the variable count by adding 1 \ No newline at end of file diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..81874537e 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,13 @@ // Predict and explain first... -// =============> write your prediction here +// Missing backticks for template string template strings need to use backticks `, but here ${} is used without them -// call the function capitalise with a string input +// call the function capitalise with a string input (error) // interpret the error message and figure out why an error is occurring +// ${} must be inside backticks and str is being redeclared (it is already the function parameter) -function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; - return str; -} // =============> write your explanation here -// =============> write your new code here +// =============> This function takes a string and returns a new string with the first letter in capital +function capitalise(str) { + return `${str[0].toUpperCase()}${str.slice(1)}`; +} diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..178ca218e 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,20 +1,15 @@ // Predict and explain first... -// Why will an error occur when this program runs? -// =============> write your prediction here +// decimalNumber is already declared as a function parameter. and name variable the same // Try playing computer with the example to work out what is going on function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; - return percentage; } -console.log(decimalNumber); - -// =============> write your explanation here +console.log(convertToPercentage(0.5)); -// Finally, correct the code to fix the problem -// =============> write your new code here +// creates a function named convertToPercentage +// The function returns the percentage string.SS diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..edebea38c 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -3,18 +3,27 @@ // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here +// Error because the variable 'num' is not defined when we try to call the function. +// The function expects +// a parameter but we're not passing any argument when calling it. -function square(3) { +function square(num) { return num * num; } -// =============> write the error message here +// The function will return NaN  (Not a Number) +// this doesn't throw an error, but returns NaN  because: +// - num is undefined (no argument passed) +// - undefined * undefined = NaN  -// =============> explain this error message here +// When square() is called without an argument, the parameter 'num' has +// // the value 'undefined'. When you multiply undefined * undefined, +// // JavaScript returns NaN (Not a Number) instead of throwing an error.  -// Finally, correct the code to fix the problem - -// =============> write your new code here +function square(num) + { + return num * num; + } + console.log(square(5)); // Output: 25 console.log(square(10));  diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..7d181fee1 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,10 @@ // Predict and explain first... -// =============> write your prediction here +//The output is 320 +//no define the reult of multiplying 10 and 32 +// This is because the multiply function uses console.log() instead of return. +// The function will print 320 to the console, but then will show +// "undefined" because the function doesn't return a value. function multiply(a, b) { console.log(a * b); @@ -10,5 +14,21 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +//The multiply() function calculates a * b (which is 320) and prints it +// using console.log(). +//console.log() doesn't return a value just output of console +// it only displays output to the console. +// +// there is no return statement, it returns 'undefined'. +// the function: +// 1. Prints "320" to the console +// 2. Returns undefined +// "The result of multiplying 10 and 32 is undefined" + // Finally, correct the code to fix the problem // =============> write your new code here + +function multiply(a, b) { + return a * b; // use return not console +} +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); \ No newline at end of file diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..2a56546f8 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,6 +1,12 @@ // Predict and explain first... // =============> write your prediction here +//The output will be: +// "The sum of 10 and 32 is not defined because the return statement without a value. +// The line "a + b;" after return will not executed +// return undefined. The code after return is unreachable. + + function sum(a, b) { return; a + b; @@ -9,5 +15,19 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +// a + b; ← This line will not executes (unreachable code) +// So the function effectively becomes: +// function sum(a, b) { +// return undefined; +// a + b; // not execute +// } +// The return statement immediately exits the function and returns undefined. +// Any code after a return statement is "unreachable" and not execute. +// result is the sum of 10 and 32 is undefined" // Finally, correct the code to fix the problem // =============> write your new code here + +function sum(a, b) { + return a + b; +} +console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..1fe93e44a 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,6 +2,13 @@ // Predict the output of the following code: // =============> Write your prediction here +//The output will be: +// The last digit of 42 is 3 +// The last digit of 105 is 3 +// The last digit of 806 is 3 +// +// All outputs show "3" because the function not taking the parameter +// passe value to 'num' (which is 103), so it returns the last digit of 103, which is 3. const num = 103; @@ -15,10 +22,34 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`); // Now run the code and compare the output to your prediction // =============> write the output here + +// The last digit of 42 is 3 +// The last digit of 105 is 3 +// The last digit of 806 is 3 // Explain why the output is the way it is // =============> write your explanation here +// The function getLastDigit() has TWO problems: +// The function definition doesn't have a parameter, +// it can't receive the values (42, 105, 806) added to it. +//inside the function, it uses the global constant +// 'num' (which is 103) instead of using the parameter +//getLastDigit(42) call function not taking 42 +// num (103) converts to "103" +// -slice(-1) gets the last character "3" +// returns "3" // Finally, correct the code to fix the problem // =============> write your new code here +const num1 = 103; +function getLastDigit(number) { // Added parameter 'number' + return number.toString().slice(-1); // Use 'number' instead of 'num' +} +console.log(`The last digit of 42 is ${getLastDigit(42)}`); +console.log(`The last digit of 105 is ${getLastDigit(105)}`); +console.log(`The last digit of 806 is ${getLastDigit(806)}`); + // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem +//The function has no parameter when call getLastDigit(42), +// the number 42 is passed but storage variable to save it. +// The function can't use it because it doesn't have a parameter to receive it. diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..614e3ecba 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -16,4 +16,7 @@ function calculateBMI(weight, height) { // return the BMI of someone based off their weight and height -} \ No newline at end of file + return Math.round((weight / (height * height)) * 10) / 10; +} + +console.log(calculateBMI(70, 1.73)); diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..cb85fac14 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,19 @@ // You will need to come up with an appropriate name for the function // Use the MDN string documentation to help you find a solution // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase + +function toUpperSnakeCase(str) { + // Step 1: Replace all spaces with _ + const withUnderscores = str.replace(/ /g, '_'); + + // Step 2: Convert to uppercase + const upperCase = withUnderscores.toUpperCase(); + + return upperCase; +} + +// Test +console.log(toUpperSnakeCase("hello there")); // "HELLO_THERE" +console.log(toUpperSnakeCase("lord of the rings")); // "LORD_OF_THE_RINGS" +console.log(toUpperSnakeCase("the quick brown fox")); // "THE_QUICK_BROWN_FOX" +console.log(toUpperSnakeCase("code your future")); // "CODE_YOUR_FUTURE" \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..bac9f3e6b 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,32 @@ // You will need to declare a function called toPounds with an appropriately named parameter. // You should call this function a number of times to check it works for different inputs + +// Function to convert pence string to pounds format +function toPounds(penceString) { + const penceStringWithoutTrailingP = penceString.substring( + 0, + penceString.length - 1 + ); + const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 + ); + const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + return `£${pounds}.${pence}`; +} + +// Test the function with inputs +console.log(toPounds("399p")); // "£3.99" +console.log(toPounds("50p")); // "£0.50" +console.log(toPounds("5p")); // "£0.05" +console.log(toPounds("1p")); // "£0.01" +console.log(toPounds("99p")); // "£0.99" +console.log(toPounds("100p")); // "£1.00" +console.log(toPounds("1250p")); // "£12.50" +console.log(toPounds("10000p")); // "£100.00" +console.log(toPounds("199p")); // "£1.99" +console.log(toPounds("2550p")); // "£25.50" diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..cb66b2ce8 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -19,16 +19,22 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +// 3 times // Call formatTimeDisplay with an input of 61, now answer the following: // b) What is the value assigned to num when pad is called for the first time? // =============> write your answer here +//0 // c) What is the return value of pad is called for the first time? // =============> write your answer here +//"00" // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer // =============> write your answer here +// 1 // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer // =============> write your answer here + +// "01" diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..1984fbea4 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -23,3 +23,27 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +// Test of existing fuction +console.log("=== TESTING BUGGY FUNCTION ==="); +console.log(formatAs12HourClock("00:00"), "→ Expected: 12:00 am ❌"); // Bug: midnight +console.log(formatAs12HourClock("12:00"), "→ Expected: 12:00 pm ❌"); // Bug: noon +console.log(formatAs12HourClock("14:30"), "→ Expected: 02:30 pm ❌"); // Bug: minutes lost +console.log(formatAs12HourClock("08:15"), "→ Expected: 08:15 am ❌"); // Bug: minutes lost +console.log(formatAs12HourClock("23:59"), "→ Expected: 11:59 pm ❌"); // Bug: minutes lost + + +// Fixed function + +function formatAs12HourClockFixed(time) { + const hours = Number(time.slice(0, 2)); + const minutes = time.slice(3, 5); + + if (hours === 0) return `12:${minutes} am`; // Midnight + if (hours === 12) return `12:${minutes} pm`; // Noon + if (hours > 12) { + const h = (hours - 12).toString().padStart(2, "0"); + return `${h}:${minutes} pm`; + } + return `${time.slice(0, 5)} am`; +} \ No newline at end of file From cb70a2187c240829038722076dd5e88d25f1e428 Mon Sep 17 00:00:00 2001 From: Alrzini2025 Date: Wed, 25 Feb 2026 11:26:17 +0000 Subject: [PATCH 02/11] I have made the correction --- Sprint-2/5-stretch-extend/format-time.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 1984fbea4..e6ddf5b6d 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -46,4 +46,5 @@ function formatAs12HourClockFixed(time) { return `${h}:${minutes} pm`; } return `${time.slice(0, 5)} am`; -} \ No newline at end of file +} + From d0df0811e59f436076e88a9542420017f8e30e0b Mon Sep 17 00:00:00 2001 From: Alrzini2025 Date: Wed, 25 Feb 2026 16:23:21 +0000 Subject: [PATCH 03/11] I made changes --- 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 e6ddf5b6d..4de6efeaa 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -33,7 +33,7 @@ console.log(formatAs12HourClock("08:15"), "→ Expected: 08:15 am ❌"); // Bug: console.log(formatAs12HourClock("23:59"), "→ Expected: 11:59 pm ❌"); // Bug: minutes lost -// Fixed function +// Fixed function to get result function formatAs12HourClockFixed(time) { const hours = Number(time.slice(0, 2)); From 1de86ca6ced8cca9a2cd0cb8504e68e1208dde06 Mon Sep 17 00:00:00 2001 From: Alrzini2025 Date: Wed, 25 Feb 2026 16:30:04 +0000 Subject: [PATCH 04/11] changes --- Sprint-2/4-mandatory-interpret/time-format.js | 2 +- Sprint-2/5-stretch-extend/format-time.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index cb66b2ce8..acd6dc3bf 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -11,7 +11,7 @@ function formatTimeDisplay(seconds) { return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } -// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit +// You will need to play computer with this example - use the Python Visual https://pythontutor.com/visualize.html#mode=edit // to help you answer these questions // Questions diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 4de6efeaa..1569c5634 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -24,7 +24,7 @@ console.assert( `current output: ${currentOutput2}, target output: ${targetOutput2}` ); -// Test of existing fuction +// Test of existing console.log("=== TESTING BUGGY FUNCTION ==="); console.log(formatAs12HourClock("00:00"), "→ Expected: 12:00 am ❌"); // Bug: midnight console.log(formatAs12HourClock("12:00"), "→ Expected: 12:00 pm ❌"); // Bug: noon From 2706654b0f1d33e1830e21770c24e9cdd40f5fcc Mon Sep 17 00:00:00 2001 From: Alrzini2025 Date: Wed, 25 Feb 2026 16:47:25 +0000 Subject: [PATCH 05/11] changes --- Sprint-2/4-mandatory-interpret/time-format.js | 2 +- Sprint-2/5-stretch-extend/format-time.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index cb66b2ce8..acd6dc3bf 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -11,7 +11,7 @@ function formatTimeDisplay(seconds) { return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } -// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit +// You will need to play computer with this example - use the Python Visual https://pythontutor.com/visualize.html#mode=edit // to help you answer these questions // Questions diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 1984fbea4..bd0ba32b0 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -24,7 +24,7 @@ console.assert( `current output: ${currentOutput2}, target output: ${targetOutput2}` ); -// Test of existing fuction +// Test of existing function console.log("=== TESTING BUGGY FUNCTION ==="); console.log(formatAs12HourClock("00:00"), "→ Expected: 12:00 am ❌"); // Bug: midnight console.log(formatAs12HourClock("12:00"), "→ Expected: 12:00 pm ❌"); // Bug: noon From da626b2fb7eb7e4eff9847e60dbbb9fbde0c9772 Mon Sep 17 00:00:00 2001 From: Alrzini2025 Date: Wed, 25 Feb 2026 17:08:52 +0000 Subject: [PATCH 06/11] I made right changes --- Sprint-1/1-key-exercises/1-count.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 20ac1f4e7..117bcb2b6 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,4 +4,3 @@ count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing -// updates the value of the variable count by adding 1 \ No newline at end of file From 632f5bea330c293a36ec16b164eb7f5e0167845b Mon Sep 17 00:00:00 2001 From: Alrzini2025 Date: Thu, 26 Feb 2026 09:17:21 +0000 Subject: [PATCH 07/11] I made changes based on review --- Sprint-2/1-key-errors/0.js | 33 +++++++++++++++++------- Sprint-2/5-stretch-extend/format-time.js | 12 +++++++++ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 81874537e..929bdf395 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,28 @@ // Predict and explain first... -// Missing backticks for template string template strings need to use backticks `, but here ${} is used without them +/// This code will error before it runs. 'str' has already been declared" +// +// This happens because: +// 1. 'str' is already declared as a function parameter +// 2. Inside the function, we try to declare 'str' again using 'let' + +// original code +//function capitalise(str) { + //let str = `${str[0].toUpperCase()}${str.slice(1)}`; +//return str; +//} -// call the function capitalise with a string input (error) -// interpret the error message and figure out why an error is occurring -// ${} must be inside backticks and str is being redeclared (it is already the function parameter) +// write your explanation here + //When you write: function capitalize(str) +// - 'str' is already declared as a parameter +//Then inside the function: let str = ... +// - This tries to declare 'str' again - -// =============> write your explanation here -// =============> This function takes a string and returns a new string with the first letter in capital +// new code function capitalise(str) { - return `${str[0].toUpperCase()}${str.slice(1)}`; -} + let capitalised = `${str[0].toUpperCase()}${str.slice(1)}`; + return capitalised; +} + +console.log(capitalise("hello")); // "Hello" + + diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index bc9f6b6b6..80ee66504 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -49,3 +49,15 @@ function formatAs12HourClockFixed(time) { return `${time.slice(0, 5)} am`; } +console.log("=== Test for fixed function ===\n"); + +console.log(formatAs12HourClockFixed("00:00"), "→ Expected: 12:00 am"); +console.log(formatAs12HourClockFixed("00:30"), "→ Expected: 12:30 am"); +console.log(formatAs12HourClockFixed("01:00"), "→ Expected: 01:00 am"); +console.log(formatAs12HourClockFixed("08:15"), "→ Expected: 08:15 am"); +console.log(formatAs12HourClockFixed("11:59"), "→ Expected: 11:59 am"); +console.log(formatAs12HourClockFixed("12:00"), "→ Expected: 12:00 pm"); +console.log(formatAs12HourClockFixed("12:30"), "→ Expected: 12:30 pm"); +console.log(formatAs12HourClockFixed("13:00"), "→ Expected: 01:00 pm"); +console.log(formatAs12HourClockFixed("14:45"), "→ Expected: 02:45 pm"); +console.log(formatAs12HourClockFixed("23:59"), "→ Expected: 11:59 pm"); From 5a0eb9470609b62e8f98abf787590512197d374a Mon Sep 17 00:00:00 2001 From: Alrzini2025 Date: Fri, 27 Feb 2026 08:56:13 +0000 Subject: [PATCH 08/11] I did sprint3 in module2 --- Sprint-3/2-practice-tdd/count.test.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf..fd7fc7c3c 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -10,13 +10,6 @@ const countChar = require("./count"); // 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"; - const count = countChar(str, char); - expect(count).toEqual(5); -}); - // Scenario: No Occurrences // Given the input string `str`, // And a character `char` that does not exist within `str`. From a8246a530fd10ddc0961747ccbb26e536ff425de Mon Sep 17 00:00:00 2001 From: Alrzini2025 Date: Fri, 27 Feb 2026 08:56:22 +0000 Subject: [PATCH 09/11] I have done all required task for sprint 3 --- .../implement/1-get-angle-type.js | 177 +++++++++++++++++- .../implement/2-is-proper-fraction.js | 34 ++++ .../implement/3-get-card-value.js | 39 ++++ Sprint-3/2-practice-tdd/count.js | 13 +- Sprint-3/2-practice-tdd/count.test.js | 10 + Sprint-3/2-practice-tdd/get-ordinal-number.js | 13 +- Sprint-3/3-dead-code/exercise-1.js | 9 +- Sprint-3/3-dead-code/exercise-2.js | 11 +- Sprint-3/4-stretch/password-validator.js | 25 ++- Sprint-3/4-stretch/password-validator.test.js | 38 +++- 10 files changed, 342 insertions(+), 27 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 9e05a871e..d137843b1 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 @@ -16,6 +16,38 @@ function getAngleType(angle) { // TODO: Implement this function + // Check for invalid angles (outside 0-360 range or negative) + if (angle <= 0 || angle >= 360) { + return "Invalid angle"; + } + + // Check for acute angle (0 < angle < 90) + if (angle < 90) { + return "Acute angle"; + } + + // Check for right angle (exactly 90) + if (angle === 90) { + return "Right angle"; + } + + // Check for obtuse angle (90 < angle < 180) + if (angle < 180) { + return "Obtuse angle"; + } + + // Check for straight angle (exactly 180) + if (angle === 180) { + return "Straight angle"; + } + + // Check for reflex angle (180 < angle < 360) + if (angle < 360) { + return "Reflex angle"; + } + + // This should not be reached due to the first check, but included for completeness + return "Invalid angle"; } // The line below allows us to load the getAngleType function into tests in other files. @@ -29,9 +61,152 @@ function assertEquals(actualOutput, targetOutput) { actualOutput === targetOutput, `Expected ${actualOutput} to equal ${targetOutput}` ); -} +} // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles + +// ============================================================ +// ACUTE ANGLE TESTS (0 < angle < 90) +// ============================================================ +console.log("--- Acute Angle Tests (0° < angle < 90°) ---"); + +const acute1 = getAngleType(1); +assertEquals(acute1, "Acute angle"); +console.log(" Test: 1° is Acute angle"); + +const acute2 = getAngleType(45); +assertEquals(acute2, "Acute angle"); +console.log(" Test: 45° is Acute angle"); + +const acute3 = getAngleType(60); +assertEquals(acute3, "Acute angle"); +console.log("Test: 60° is Acute angle"); + +const acute4 = getAngleType(89); +assertEquals(acute4, "Acute angle"); +console.log(" Test: 89° is Acute angle (boundary - just below 90°)"); + +const acute5 = getAngleType(0.5); +assertEquals(acute5, "Acute angle"); +console.log(" Test: 0.5° is Acute angle (decimal)"); + +// ============================================================ +// RIGHT ANGLE TEST (exactly 90) +// ============================================================ +console.log("\n--- Right Angle Test (exactly 90°) ---"); + const right = getAngleType(90); assertEquals(right, "Right angle"); +console.log(" Test: 90° is Right angle"); + +// ============================================================ +// OBTUSE ANGLE TESTS (90 < angle < 180) +// ============================================================ +console.log("\n--- Obtuse Angle Tests (90° < angle < 180°) ---"); + +const obtuse1 = getAngleType(91); +assertEquals(obtuse1, "Obtuse angle"); +console.log(" Test: 91° is Obtuse angle (boundary - just above 90°)"); + +const obtuse2 = getAngleType(120); +assertEquals(obtuse2, "Obtuse angle"); +console.log(" Test: 120° is Obtuse angle"); + +const obtuse3 = getAngleType(135); +assertEquals(obtuse3, "Obtuse angle"); +console.log(" Test: 135° is Obtuse angle"); + +const obtuse4 = getAngleType(179); +assertEquals(obtuse4, "Obtuse angle"); +console.log(" Test: 179° is Obtuse angle (boundary - just below 180°)"); + +const obtuse5 = getAngleType(150.5); +assertEquals(obtuse5, "Obtuse angle"); +console.log(" Test: 150.5° is Obtuse angle (decimal)"); + +// ============================================================ +// STRAIGHT ANGLE TEST (exactly 180) +// ============================================================ +console.log("\n--- Straight Angle Test (exactly 180°) ---"); + +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); +console.log(" Test: 180° is Straight angle"); + +// ============================================================ +// REFLEX ANGLE TESTS (180 < angle < 360) +// ============================================================ +console.log("\n--- Reflex Angle Tests (180° < angle < 360°) ---"); + +const reflex1 = getAngleType(181); +assertEquals(reflex1, "Reflex angle"); +console.log(" Test: 181° is Reflex angle (boundary - just above 180°)"); + +const reflex2 = getAngleType(200); +assertEquals(reflex2, "Reflex angle"); +console.log(" Test: 200° is Reflex angle"); + +const reflex3 = getAngleType(270); +assertEquals(reflex3, "Reflex angle"); +console.log(" Test: 270° is Reflex angle"); + +const reflex4 = getAngleType(300); +assertEquals(reflex4, "Reflex angle"); +console.log(" Test: 300° is Reflex angle"); + +const reflex5 = getAngleType(359); +assertEquals(reflex5, "Reflex angle"); +console.log(" Test: 359° is Reflex angle (boundary - just below 360°)"); + +const reflex6 = getAngleType(225.7); +assertEquals(reflex6, "Reflex angle"); +console.log(" Test: 225.7° is Reflex angle (decimal)"); + +// ============================================================ +// INVALID ANGLE TESTS +// ============================================================ +console.log("\n--- Invalid Angle Tests ---"); + +// Zero +const invalid1 = getAngleType(0); +assertEquals(invalid1, "Invalid angle"); +console.log(" Test: 0° is Invalid angle"); + +// Negative angles +const invalid2 = getAngleType(-1); +assertEquals(invalid2, "Invalid angle"); +console.log(" Test: -1° is Invalid angle"); + +const invalid3 = getAngleType(-45); +assertEquals(invalid3, "Invalid angle"); +console.log(" Test: -45° is Invalid angle"); + +const invalid4 = getAngleType(-90); +assertEquals(invalid4, "Invalid angle"); +console.log(" Test: -90° is Invalid angle"); + +const invalid5 = getAngleType(-180); +assertEquals(invalid5, "Invalid angle"); +console.log(" Test: -180° is Invalid angle"); + +// 360 and above +const invalid6 = getAngleType(360); +assertEquals(invalid6, "Invalid angle"); +console.log(" Test: 360° is Invalid angle (boundary)"); + +const invalid7 = getAngleType(361); +assertEquals(invalid7, "Invalid angle"); +console.log(" Test: 361° is Invalid angle"); + +const invalid8 = getAngleType(400); +assertEquals(invalid8, "Invalid angle"); +console.log(" Test: 400° is Invalid angle"); + +const invalid9 = getAngleType(720); +assertEquals(invalid9, "Invalid angle"); +console.log(" Test: 720° is Invalid angle (full rotation)"); + +const invalid10 = getAngleType(1000); +assertEquals(invalid10, "Invalid angle"); +console.log(" Test: 1000° is Invalid angle"); 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 970cb9b64..d0fd507aa 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 @@ -12,8 +12,17 @@ function isProperFraction(numerator, denominator) { // TODO: Implement this function + // Denominator cannot be zero + if (denominator === 0) { + return false; + } + + return Math.abs(numerator) < Math.abs(denominator); } +module.exports = isProperFraction; + + // 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; @@ -31,3 +40,28 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); + +// 2. Improper fraction +assertEquals(isProperFraction(3, 2), false); + +// 3. Equal numerator & denominator +assertEquals(isProperFraction(2, 2), false); + +// 4. Negative numerator +assertEquals(isProperFraction(-1, 2), true); + +// 5. Negative denominator +assertEquals(isProperFraction(1, -2), true); + +// 6. Both negative +assertEquals(isProperFraction(-1, -2), true); + +// 7. Zero numerator +assertEquals(isProperFraction(0, 5), true); + +// 8. Zero denominator (invalid fraction) +assertEquals(isProperFraction(5, 0), false); + +console.log("All tests executed"); + + 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 c7559e787..709339a96 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 @@ -50,3 +50,42 @@ try { } catch (e) {} // What other invalid card cases can you think of? +// Invalid cards + +// Invalid string +try { + getCardValue("invalid"); + console.error("Error not thrown for invalid string"); +} catch (e) {} + +// Invalid suit +try { + getCardValue("A?"); + console.error("Error not thrown for invalid suit"); +} catch (e) {} + +// Invalid rank +try { + getCardValue("1♠"); + console.error("Error not thrown for invalid rank"); +} catch (e) {} + +// Missing suit +try { + getCardValue("A"); + console.error("Error not thrown for missing suit"); +} catch (e) {} + +// Empty string +try { + getCardValue(""); + console.error("Error not thrown for empty string"); +} catch (e) {} + +// Not a string +try { + getCardValue(123); + console.error("Error not thrown for non-string input"); +} catch (e) {} + +console.log("All tests executed"); \ No newline at end of file diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d..317b67018 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,14 @@ -function countChar(stringOfCharacters, findCharacter) { - return 5 + +function countChar(str, char) { + let count = 0; + + for (let i = 0; i < str.length; i++) { + if (str[i] === char) { + count++; + } + } + + return count; } module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index fd7fc7c3c..d4eabfbd7 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -1,5 +1,15 @@ // implement a function countChar that counts the number of times a character occurs in a string + const countChar = require("./count"); + +test("should count multiple occurrences of a character", () => { + expect(countChar("aaaaa", "a")).toEqual(5); +}); + +test("should return 0 when character is not found", () => { + expect(countChar("hello", "z")).toEqual(0); +}); + // Given a string `str` and a single character `char` to search for, // When the countChar function is called with these inputs, // Then it should: diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db1..7f655e042 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,16 @@ function getOrdinalNumber(num) { - return "1st"; + const lastTwoDigits = num % 100; + const lastDigit = num % 10; + + if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { + return `${num}th`; + } + + if (lastDigit === 1) return `${num}st`; + if (lastDigit === 2) return `${num}nd`; + if (lastDigit === 3) return `${num}rd`; + + return `${num}th`; } module.exports = getOrdinalNumber; diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js index 4d09f15fa..48973d801 100644 --- a/Sprint-3/3-dead-code/exercise-1.js +++ b/Sprint-3/3-dead-code/exercise-1.js @@ -1,15 +1,14 @@ // Find the instances of unreachable and redundant code - remove them! -// The sayHello function should continue to work for any reasonable input it's given. -let testName = "Jerry"; -const greeting = "hello"; +// The sayHello function should continue to work for any reasonable input it's given. function sayHello(greeting, name) { - const greetingStr = greeting + ", " + name + "!"; return `${greeting}, ${name}!`; - console.log(greetingStr); } +let testName = "Jerry"; +const greeting = "hello"; + testName = "Aman"; const greetingMessage = sayHello(greeting, testName); diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js index 56d7887c4..2010485b4 100644 --- a/Sprint-3/3-dead-code/exercise-2.js +++ b/Sprint-3/3-dead-code/exercise-2.js @@ -2,27 +2,26 @@ // 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)); -} +const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); function countAndCapitalisePets(petsArr) { const petCount = {}; petsArr.forEach((pet) => { const capitalisedPet = pet.toUpperCase(); + if (petCount[capitalisedPet]) { petCount[capitalisedPet] += 1; } else { petCount[capitalisedPet] = 1; } }); + return petCount; } const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH); -console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log +console.log(countedPetsStartingWithH); +// { 'HAMSTER': 3, 'HORSE': 1 } diff --git a/Sprint-3/4-stretch/password-validator.js b/Sprint-3/4-stretch/password-validator.js index b55d527db..062a1dc44 100644 --- a/Sprint-3/4-stretch/password-validator.js +++ b/Sprint-3/4-stretch/password-validator.js @@ -1,6 +1,25 @@ function passwordValidator(password) { - return password.length < 5 ? false : true -} + const previousPasswords = ["Password1!", "Welcome1$", "Admin123!"]; + + // Rule 1: Minimum length + if (password.length < 5) return false; + + // Rule 2: Uppercase + if (!/[A-Z]/.test(password)) return false; + + // Rule 3: Lowercase + if (!/[a-z]/.test(password)) return false; + // Rule 4: Number + if (!/[0-9]/.test(password)) return false; + + // Rule 5: Special character + if (!/[!#$%.*&]/.test(password)) return false; + + // Rule 6: Not a previous password + if (previousPasswords.includes(password)) return false; + + return true; +} -module.exports = passwordValidator; \ No newline at end of file +module.exports = passwordValidator; diff --git a/Sprint-3/4-stretch/password-validator.test.js b/Sprint-3/4-stretch/password-validator.test.js index 8fa3089d6..082a4462c 100644 --- a/Sprint-3/4-stretch/password-validator.test.js +++ b/Sprint-3/4-stretch/password-validator.test.js @@ -15,12 +15,32 @@ To be valid, a password must: You must breakdown this problem in order to solve it. Find one test case first and get that working */ const isValidPassword = require("./password-validator"); -test("password has at least 5 characters", () => { - // Arrange - const password = "12345"; - // Act - const result = isValidPassword(password); - // Assert - expect(result).toEqual(true); -} -); \ No newline at end of file +test("valid password passes validation", () => { + const password = "Abc1!"; // meets all rules + const result = isValidPassword(password); + expect(result).toEqual(true); +}); + +test("password too short fails", () => { + expect(isValidPassword("A1!b")).toBe(false); +}); + +test("password without uppercase fails", () => { + expect(isValidPassword("abc1!")).toBe(false); +}); + +test("password without lowercase fails", () => { + expect(isValidPassword("ABC1!")).toBe(false); +}); + +test("password without number fails", () => { + expect(isValidPassword("Abcde!")).toBe(false); +}); + +test("password without special char fails", () => { + expect(isValidPassword("Abcde1")).toBe(false); +}); + +test("password previously used fails", () => { + expect(isValidPassword("Password1!")).toBe(false); +}); From f21578b054c3402453922b0060d320cf359dc355 Mon Sep 17 00:00:00 2001 From: Alrzini2025 Date: Fri, 27 Feb 2026 09:07:14 +0000 Subject: [PATCH 10/11] changes in Sprint 3 --- Sprint-3/4-stretch/password-validator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/4-stretch/password-validator.js b/Sprint-3/4-stretch/password-validator.js index 062a1dc44..64cd2b70c 100644 --- a/Sprint-3/4-stretch/password-validator.js +++ b/Sprint-3/4-stretch/password-validator.js @@ -4,7 +4,7 @@ function passwordValidator(password) { // Rule 1: Minimum length if (password.length < 5) return false; - // Rule 2: Uppercase + // Rule 2: Uppercases if (!/[A-Z]/.test(password)) return false; // Rule 3: Lowercase From 9a6928c95766338d56cd3a361c84bff6e3d088c9 Mon Sep 17 00:00:00 2001 From: Alrzini2025 Date: Fri, 27 Feb 2026 17:28:25 +0000 Subject: [PATCH 11/11] changes for sprint-3 --- .../implement/1-get-angle-type.js | 177 +----------------- .../implement/2-is-proper-fraction.js | 34 ---- .../implement/3-get-card-value.js | 39 ---- Sprint-3/2-practice-tdd/count.js | 13 +- Sprint-3/2-practice-tdd/count.test.js | 17 +- Sprint-3/2-practice-tdd/get-ordinal-number.js | 13 +- 6 files changed, 11 insertions(+), 282 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 d137843b1..9e05a871e 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 @@ -16,38 +16,6 @@ function getAngleType(angle) { // TODO: Implement this function - // Check for invalid angles (outside 0-360 range or negative) - if (angle <= 0 || angle >= 360) { - return "Invalid angle"; - } - - // Check for acute angle (0 < angle < 90) - if (angle < 90) { - return "Acute angle"; - } - - // Check for right angle (exactly 90) - if (angle === 90) { - return "Right angle"; - } - - // Check for obtuse angle (90 < angle < 180) - if (angle < 180) { - return "Obtuse angle"; - } - - // Check for straight angle (exactly 180) - if (angle === 180) { - return "Straight angle"; - } - - // Check for reflex angle (180 < angle < 360) - if (angle < 360) { - return "Reflex angle"; - } - - // This should not be reached due to the first check, but included for completeness - return "Invalid angle"; } // The line below allows us to load the getAngleType function into tests in other files. @@ -61,152 +29,9 @@ function assertEquals(actualOutput, targetOutput) { actualOutput === targetOutput, `Expected ${actualOutput} to equal ${targetOutput}` ); -} +} // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles - -// ============================================================ -// ACUTE ANGLE TESTS (0 < angle < 90) -// ============================================================ -console.log("--- Acute Angle Tests (0° < angle < 90°) ---"); - -const acute1 = getAngleType(1); -assertEquals(acute1, "Acute angle"); -console.log(" Test: 1° is Acute angle"); - -const acute2 = getAngleType(45); -assertEquals(acute2, "Acute angle"); -console.log(" Test: 45° is Acute angle"); - -const acute3 = getAngleType(60); -assertEquals(acute3, "Acute angle"); -console.log("Test: 60° is Acute angle"); - -const acute4 = getAngleType(89); -assertEquals(acute4, "Acute angle"); -console.log(" Test: 89° is Acute angle (boundary - just below 90°)"); - -const acute5 = getAngleType(0.5); -assertEquals(acute5, "Acute angle"); -console.log(" Test: 0.5° is Acute angle (decimal)"); - -// ============================================================ -// RIGHT ANGLE TEST (exactly 90) -// ============================================================ -console.log("\n--- Right Angle Test (exactly 90°) ---"); - const right = getAngleType(90); assertEquals(right, "Right angle"); -console.log(" Test: 90° is Right angle"); - -// ============================================================ -// OBTUSE ANGLE TESTS (90 < angle < 180) -// ============================================================ -console.log("\n--- Obtuse Angle Tests (90° < angle < 180°) ---"); - -const obtuse1 = getAngleType(91); -assertEquals(obtuse1, "Obtuse angle"); -console.log(" Test: 91° is Obtuse angle (boundary - just above 90°)"); - -const obtuse2 = getAngleType(120); -assertEquals(obtuse2, "Obtuse angle"); -console.log(" Test: 120° is Obtuse angle"); - -const obtuse3 = getAngleType(135); -assertEquals(obtuse3, "Obtuse angle"); -console.log(" Test: 135° is Obtuse angle"); - -const obtuse4 = getAngleType(179); -assertEquals(obtuse4, "Obtuse angle"); -console.log(" Test: 179° is Obtuse angle (boundary - just below 180°)"); - -const obtuse5 = getAngleType(150.5); -assertEquals(obtuse5, "Obtuse angle"); -console.log(" Test: 150.5° is Obtuse angle (decimal)"); - -// ============================================================ -// STRAIGHT ANGLE TEST (exactly 180) -// ============================================================ -console.log("\n--- Straight Angle Test (exactly 180°) ---"); - -const straight = getAngleType(180); -assertEquals(straight, "Straight angle"); -console.log(" Test: 180° is Straight angle"); - -// ============================================================ -// REFLEX ANGLE TESTS (180 < angle < 360) -// ============================================================ -console.log("\n--- Reflex Angle Tests (180° < angle < 360°) ---"); - -const reflex1 = getAngleType(181); -assertEquals(reflex1, "Reflex angle"); -console.log(" Test: 181° is Reflex angle (boundary - just above 180°)"); - -const reflex2 = getAngleType(200); -assertEquals(reflex2, "Reflex angle"); -console.log(" Test: 200° is Reflex angle"); - -const reflex3 = getAngleType(270); -assertEquals(reflex3, "Reflex angle"); -console.log(" Test: 270° is Reflex angle"); - -const reflex4 = getAngleType(300); -assertEquals(reflex4, "Reflex angle"); -console.log(" Test: 300° is Reflex angle"); - -const reflex5 = getAngleType(359); -assertEquals(reflex5, "Reflex angle"); -console.log(" Test: 359° is Reflex angle (boundary - just below 360°)"); - -const reflex6 = getAngleType(225.7); -assertEquals(reflex6, "Reflex angle"); -console.log(" Test: 225.7° is Reflex angle (decimal)"); - -// ============================================================ -// INVALID ANGLE TESTS -// ============================================================ -console.log("\n--- Invalid Angle Tests ---"); - -// Zero -const invalid1 = getAngleType(0); -assertEquals(invalid1, "Invalid angle"); -console.log(" Test: 0° is Invalid angle"); - -// Negative angles -const invalid2 = getAngleType(-1); -assertEquals(invalid2, "Invalid angle"); -console.log(" Test: -1° is Invalid angle"); - -const invalid3 = getAngleType(-45); -assertEquals(invalid3, "Invalid angle"); -console.log(" Test: -45° is Invalid angle"); - -const invalid4 = getAngleType(-90); -assertEquals(invalid4, "Invalid angle"); -console.log(" Test: -90° is Invalid angle"); - -const invalid5 = getAngleType(-180); -assertEquals(invalid5, "Invalid angle"); -console.log(" Test: -180° is Invalid angle"); - -// 360 and above -const invalid6 = getAngleType(360); -assertEquals(invalid6, "Invalid angle"); -console.log(" Test: 360° is Invalid angle (boundary)"); - -const invalid7 = getAngleType(361); -assertEquals(invalid7, "Invalid angle"); -console.log(" Test: 361° is Invalid angle"); - -const invalid8 = getAngleType(400); -assertEquals(invalid8, "Invalid angle"); -console.log(" Test: 400° is Invalid angle"); - -const invalid9 = getAngleType(720); -assertEquals(invalid9, "Invalid angle"); -console.log(" Test: 720° is Invalid angle (full rotation)"); - -const invalid10 = getAngleType(1000); -assertEquals(invalid10, "Invalid angle"); -console.log(" Test: 1000° is Invalid angle"); 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 d0fd507aa..970cb9b64 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 @@ -12,17 +12,8 @@ function isProperFraction(numerator, denominator) { // TODO: Implement this function - // Denominator cannot be zero - if (denominator === 0) { - return false; - } - - return Math.abs(numerator) < Math.abs(denominator); } -module.exports = isProperFraction; - - // 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; @@ -40,28 +31,3 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); - -// 2. Improper fraction -assertEquals(isProperFraction(3, 2), false); - -// 3. Equal numerator & denominator -assertEquals(isProperFraction(2, 2), false); - -// 4. Negative numerator -assertEquals(isProperFraction(-1, 2), true); - -// 5. Negative denominator -assertEquals(isProperFraction(1, -2), true); - -// 6. Both negative -assertEquals(isProperFraction(-1, -2), true); - -// 7. Zero numerator -assertEquals(isProperFraction(0, 5), true); - -// 8. Zero denominator (invalid fraction) -assertEquals(isProperFraction(5, 0), false); - -console.log("All tests executed"); - - 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 709339a96..c7559e787 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 @@ -50,42 +50,3 @@ try { } catch (e) {} // What other invalid card cases can you think of? -// Invalid cards - -// Invalid string -try { - getCardValue("invalid"); - console.error("Error not thrown for invalid string"); -} catch (e) {} - -// Invalid suit -try { - getCardValue("A?"); - console.error("Error not thrown for invalid suit"); -} catch (e) {} - -// Invalid rank -try { - getCardValue("1♠"); - console.error("Error not thrown for invalid rank"); -} catch (e) {} - -// Missing suit -try { - getCardValue("A"); - console.error("Error not thrown for missing suit"); -} catch (e) {} - -// Empty string -try { - getCardValue(""); - console.error("Error not thrown for empty string"); -} catch (e) {} - -// Not a string -try { - getCardValue(123); - console.error("Error not thrown for non-string input"); -} catch (e) {} - -console.log("All tests executed"); \ No newline at end of file diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 317b67018..95b6ebb7d 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,14 +1,5 @@ - -function countChar(str, char) { - let count = 0; - - for (let i = 0; i < str.length; i++) { - if (str[i] === char) { - count++; - } - } - - return count; +function countChar(stringOfCharacters, findCharacter) { + return 5 } module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index d4eabfbd7..179ea0ddf 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -1,15 +1,5 @@ // implement a function countChar that counts the number of times a character occurs in a string - const countChar = require("./count"); - -test("should count multiple occurrences of a character", () => { - expect(countChar("aaaaa", "a")).toEqual(5); -}); - -test("should return 0 when character is not found", () => { - expect(countChar("hello", "z")).toEqual(0); -}); - // Given a string `str` and a single character `char` to search for, // When the countChar function is called with these inputs, // Then it should: @@ -20,6 +10,13 @@ test("should return 0 when character is not found", () => { // 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"; + const count = countChar(str, char); + expect(count).toEqual(5); +}); + // Scenario: No Occurrences // Given the input string `str`, // And a character `char` that does not exist within `str`. diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index 7f655e042..f95d71db1 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,16 +1,5 @@ function getOrdinalNumber(num) { - const lastTwoDigits = num % 100; - const lastDigit = num % 10; - - if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { - return `${num}th`; - } - - if (lastDigit === 1) return `${num}st`; - if (lastDigit === 2) return `${num}nd`; - if (lastDigit === 3) return `${num}rd`; - - return `${num}th`; + return "1st"; } module.exports = getOrdinalNumber;