From 135ce97ffe579f28b37ac5c7a59a191546c5a05d Mon Sep 17 00:00:00 2001 From: Shuheda Date: Wed, 18 Feb 2026 14:01:11 +0000 Subject: [PATCH 01/26] Update 0.js Questions Answered --- Sprint-2/1-key-errors/0.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..1a2131a0d 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... -// =============> write your prediction here +// I predict when this code runs, there will be a SyntaxError before the function executes. +// This is because the identifier 'str' has already been declared. // call the function capitalise with a string input +// capitalise("hello"); + + // interpret the error message and figure out why an error is occurring +// Uncaught SyntaxError: Unexpected identifier 'string' - this is the error message. +// This error is occuring because the variable 'str' is being redeclared within the function, which is not allowed in JavaScript. +// The duplicate use if 'str' is causing the syntax error. + + +//function capitalise(str) { + //let str = `${str[0].toUpperCase()}${str.slice(1)}`; + //return str; +//} + +// The issue is variable redeclaration. +// str is the function parameter. +// let str tries to create a new variable with the same name. +// JavaScript does not allow redeclaring a variable in the same scope. +// As a result, the code throws a SyntaxError when it encounters the second 'str' declaration. + +// New code without the error: -function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; - return str; -} -// =============> write your explanation here -// =============> write your new code here From 4cdd2ce7344ac71e2953cb652c0dcab7d9f4662b Mon Sep 17 00:00:00 2001 From: Shuheda Date: Wed, 18 Feb 2026 14:14:16 +0000 Subject: [PATCH 02/26] Update 0.js Fixed code and tested. --- Sprint-2/1-key-errors/0.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 1a2131a0d..434814849 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -25,4 +25,17 @@ // New code without the error: +// 0.js — fully fixed version +function capitalise(str) { + if (!str) return str; // handles empty string + return str[0].toUpperCase() + str.slice(1); +} + +// Test it +console.log(capitalise("hello")); // should print "Hello" +console.log(capitalise("world")); // should print "World" +console.log(capitalise("")); // should print "" + + + From 0ebb92fecf354a150e074de6aecd6ae4e0a893bc Mon Sep 17 00:00:00 2001 From: Shuheda Date: Thu, 19 Feb 2026 01:18:52 +0000 Subject: [PATCH 03/26] Update 1.js Added my prediction --- Sprint-2/1-key-errors/1.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..ea8c2c257 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,9 +1,9 @@ // Predict and explain first... - // Why will an error occur when this program runs? -// =============> write your prediction here +// I predict an error will occur when this program runs because the variable 'decimalNumber' is already declared inside the function 'convertToPercentage' and cannot be redeclared. // Try playing computer with the example to work out what is going on +// When the 'function convertToPercentage(decimalNumber)' is created, Javascript already creates a variable called decimalNumber. then, inside the function, 'const decimalNumber = 0.5' tries to create another variable with the same name. This casues a syntax error because you cannot declare two variables with the same name in the same scope. function convertToPercentage(decimalNumber) { const decimalNumber = 0.5; From 794f136aed1f5dcd5f3b98d0ec5fe5021818d567 Mon Sep 17 00:00:00 2001 From: Shuheda Date: Thu, 19 Feb 2026 01:30:37 +0000 Subject: [PATCH 04/26] Update 1.js Code amended and working. --- Sprint-2/1-key-errors/1.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index ea8c2c257..1c0cbb33c 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -5,16 +5,25 @@ // Try playing computer with the example to work out what is going on // When the 'function convertToPercentage(decimalNumber)' is created, Javascript already creates a variable called decimalNumber. then, inside the function, 'const decimalNumber = 0.5' tries to create another variable with the same name. This casues a syntax error because you cannot declare two variables with the same name in the same scope. -function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; - const percentage = `${decimalNumber * 100}%`; +// function convertToPercentage(decimalNumber) { + // const decimalNumber = 0.5; + // const percentage = `${decimalNumber * 100}%`; - return percentage; -} + // return percentage; +// } -console.log(decimalNumber); +// console.log(decimalNumber); -// =============> write your explanation here +// Write your explanation here +// I redelcared the parameter decimalNumber using const. +// I tried to log decimalNumber outside its scope. +// The variables declared inside the function are not available outside unless they are returned. // Finally, correct the code to fix the problem -// =============> write your new code here + +function convertToPercentage(decimalNumber) { + const percentage = `${decimalNumber * 100}%`; + return percentage; +} + +console.log(convertToPercentage(0.5)); // "50%" From 364c15c8c2f076e932e8651dc6929f6eee45609b Mon Sep 17 00:00:00 2001 From: Shuheda Date: Thu, 19 Feb 2026 01:47:28 +0000 Subject: [PATCH 05/26] Update 2.js Explanation of syntax error and new code --- Sprint-2/1-key-errors/2.js | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..a6183a5c6 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,20 +1,32 @@ // Predict and explain first BEFORE you run any code... +// This function should square any number but instead we're going to get an error -// this function should square any number but instead we're going to get an error +// Write your prediction of the error here: +// I predict that the error will be a syntax error because the parameter '3' is not a valid variable name. +// When you define a function,, the thing inside the parentahese must be a parameter name, NOT a number. -// =============> write your prediction of the error here +// function square(3) { + // return num * num; +// } -function square(3) { - return num * num; -} +// Write the error message here +// SyntaxError: Unexpected number -// =============> write the error message here - -// =============> explain this error message here +// Explain the error messge here: +// When defining a function, inside the parentheses, you need to put a parameter name, which is a variable. +// In this case, '3' is not a valid parameter name because it is a number, not a variable. +// This causes a syntax error because Javascript expects a name, not a number. // Finally, correct the code to fix the problem +// Write your new code here + +function square(num) { + return num * num; +} + +console.log(square(3)); // 9 +console.log(square(5)); // 25 -// =============> write your new code here From c648393060c1fdec2ca53c408909473fff45cf8b Mon Sep 17 00:00:00 2001 From: Shuheda Date: Thu, 19 Feb 2026 22:05:15 +0000 Subject: [PATCH 06/26] Sprint 2 0.js Prediction and explanation --- Sprint-2/2-mandatory-debug/0.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..26f828c88 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,5 @@ -// Predict and explain first... - -// =============> write your prediction here +// Predict and explain first...write your prediction here +// I predict, when the code runs, it will print 320, but it will also print "The result of multiplying 10 and 32 is undefined". function multiply(a, b) { console.log(a * b); @@ -8,7 +7,10 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// =============> write your explanation here +// Write your explanation here +// The function multiply(a, b) logs the result of a * b to the console but does not return a value. +// When multiply(10, 32) is called within the template literal, it logs 320 to the console but returns undefined. +// Therefore, inside the template literal, the value is undefined, which is why the final output becomes "The result of multiplying 10 and 32 is undefined". // Finally, correct the code to fix the problem // =============> write your new code here From 6223c28b6afe8fbfb5dcc3aa9579694ff732aa2b Mon Sep 17 00:00:00 2001 From: Shuheda Date: Thu, 19 Feb 2026 22:17:07 +0000 Subject: [PATCH 07/26] Sprint 2 0.js New Code --- Sprint-2/2-mandatory-debug/0.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index 26f828c88..51ce1ba85 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,11 +1,11 @@ // Predict and explain first...write your prediction here // I predict, when the code runs, it will print 320, but it will also print "The result of multiplying 10 and 32 is undefined". -function multiply(a, b) { - console.log(a * b); -} +//function multiply(a, b) { +// console.log(a * b); +// } -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); +// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // Write your explanation here // The function multiply(a, b) logs the result of a * b to the console but does not return a value. @@ -13,4 +13,12 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // Therefore, inside the template literal, the value is undefined, which is why the final output becomes "The result of multiplying 10 and 32 is undefined". // Finally, correct the code to fix the problem -// =============> write your new code here +// Write your new code here +// To fix the problem, the function should return the result instead of logging it. + +function multiply(a, b) { + return a * b; +} + +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); + From e38cd413c4635bd6523c385329eba3ac024e54d7 Mon Sep 17 00:00:00 2001 From: Shuheda Date: Thu, 19 Feb 2026 22:32:30 +0000 Subject: [PATCH 08/26] Sprint 2 1.js Prediction and explanation --- Sprint-2/2-mandatory-debug/1.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..17e226123 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,5 @@ -// Predict and explain first... -// =============> write your prediction here +// Predict and explain first...write your prediction here +// I think the code will return undefined. function sum(a, b) { return; @@ -8,6 +8,10 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); -// =============> write your explanation here +// Write your explanation here +// When JavaScript sees the 'return' statement, it immediately stopd the function. It does NOT continue to the next line. +// So this part, 'a+b;' never runs. To return the sum of a and b, we need to put it on the same line as the return. +// Like the: 'return a + b;' + // Finally, correct the code to fix the problem // =============> write your new code here From a6caa895fb60c5a6540ac91f3dac9f6eff2dc1b6 Mon Sep 17 00:00:00 2001 From: Shuheda Date: Thu, 19 Feb 2026 22:34:13 +0000 Subject: [PATCH 09/26] Sprint 1.js New code updated --- Sprint-2/2-mandatory-debug/1.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 17e226123..97b068aba 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,12 +1,12 @@ // Predict and explain first...write your prediction here // I think the code will return undefined. -function sum(a, b) { - return; - a + b; -} +//function sum(a, b) { + // return; + // a + b; +//} -console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); +//console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // Write your explanation here // When JavaScript sees the 'return' statement, it immediately stopd the function. It does NOT continue to the next line. @@ -15,3 +15,9 @@ console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // 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)}`); From 937eb3a070de5d16c8fdcbc3bb145aa032051312 Mon Sep 17 00:00:00 2001 From: Shuheda Date: Thu, 19 Feb 2026 22:52:54 +0000 Subject: [PATCH 10/26] Sprint 2.js Predicted, anded explanation and fixed code. --- Sprint-2/2-mandatory-debug/2.js | 39 ++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..e180de334 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,24 +1,43 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// Write your prediction here +// I think the output will be 'The last digit of 42 is 2', 'The last digit of 105 is 5', and 'The last digit of 806 is 6'. +// I think this will happen because the getLastDigit function is supposed to take a number, convert it to a string, and then return the last charecter of that string, which should be the last digit. -const num = 103; +//const num = 103; -function getLastDigit() { - return num.toString().slice(-1); +//function getLastDigit() { +// return num.toString().slice(-1); +//} + +//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)}`); + +// Now run the code and compare the output to your prediction +// Write the output here +// The output is: +// 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 output is 3 for all numbers because the function getLastDigit is not taking any parameters. It always uses the global variable `num` which is set to 103. So it always returns the last digit of 103, which is 3. + +// Finally, correct the code to fix the problem +// Write your new code here + +function getLastDigit(number) { + return number.toString().slice(-1); } 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)}`); -// Now run the code and compare the output to your prediction -// =============> write the output here -// Explain why the output is the way it is -// =============> write your explanation here -// Finally, correct the code to fix the problem -// =============> write your new code here // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem +// The funtion did not accept a parameter. It was a fixed variable (num = 103), so it always returned the last digit of 103. \ No newline at end of file From e6467fb8620b0d34de5aed9da5ae852cae160c18 Mon Sep 17 00:00:00 2001 From: Shuheda Date: Thu, 19 Feb 2026 23:15:36 +0000 Subject: [PATCH 11/26] Sprint 2 2.js Fixed spelling --- Sprint-2/2-mandatory-debug/2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index e180de334..1819a950d 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -40,4 +40,4 @@ 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 funtion did not accept a parameter. It was a fixed variable (num = 103), so it always returned the last digit of 103. \ No newline at end of file +// The function did not accept a parameter. It was a fixed variable (num = 103), so it always returned the last digit of 103. \ No newline at end of file From b4c367d965c8c4f52b5362bace50fd424c105e41 Mon Sep 17 00:00:00 2001 From: Shuheda Date: Thu, 19 Feb 2026 23:39:29 +0000 Subject: [PATCH 12/26] Sprint 2 1-bmi.js Made notes and built a code to calculate bmi. --- Sprint-2/3-mandatory-implement/1-bmi.js | 28 +++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..c2b35cc71 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -14,6 +14,30 @@ // Then when we call this function with the weight and height // It should return their Body Mass Index to 1 decimal place -function calculateBMI(weight, height) { +//function calculateBMI(weight, height) { // return the BMI of someone based off their weight and height -} \ No newline at end of file +// } + +// Notes: +// BMI = weight ÷ (height x height) +// eg. BMI = 70kg ÷ (1.73m x 1.73) +// BMI = 70kg ÷ 2.99 +// BMI = 23.41 +// BMI = 23.4 (to 1 decimal place) + +// I need to: +// 1. Square the height +// 2. Divide weight by squared height +// 3. Round the result to 1 decimal place +// 4. Return the result + +function calculateBMI(weight, height) { + const bmi = weight / (height * height); + return bmi.toFixed(1); +} + +console.log(calculateBMI(70, 1.73)); + + + +//toFixed(1) tells JavaScript to round the number to 1 decimal place. \ No newline at end of file From 5ede344ba4d9b1dddc2933ab30e9156fa2dd27cb Mon Sep 17 00:00:00 2001 From: Shuheda Date: Fri, 20 Feb 2026 00:04:00 +0000 Subject: [PATCH 13/26] Sprint 2 2-cases.js Made notes for code requirements. Used MDN. Developed code that runs. --- Sprint-2/3-mandatory-implement/2-cases.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..180b793b5 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,24 @@ // 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 + +// NOTES: +// "hello there" should become "HELLO_THERE" +// I need to turn all letters into CAPITALS and replace the space " " with underscore "-" + +// From the MDN documentation: +// I can use the toUpperCase() to turn the tring into all CAPS. +// I can use the replaceAll() to replace all the spaces with underscores. + +// Good function name: +// toUpperSnakeCase - this name is decriptive and indicates that the function will convert a string to upper snake case. + +function toUpperSnakeCase(str) { + return str.toUpperCase().replaceAll(" ", "_"); +} + +console.log(toUpperSnakeCase("hello there")); +// HELLO_THERE + +console.log(toUpperSnakeCase("lord of the rings")); +// LORD_OF_THE_RINGS From 8bd53285f84b8573e21d8f19139a9017170b9f75 Mon Sep 17 00:00:00 2001 From: Shuheda Date: Fri, 20 Feb 2026 00:22:35 +0000 Subject: [PATCH 14/26] Update 3-to-pounds.js Located original code Made notes Worked on a code --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..88942684e 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -1,6 +1,62 @@ // In Sprint-1, there is a program written in interpret/to-pounds.js +// ORIGINAL CODE: +//const penceString = "399p"; + +//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"); + +//console.log(`£${pounds}.${pence}`); + + // You will need to take this code and turn it into a reusable block of code. // 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 +// You should call this function a number of times to check it works for different inputs. +// For example: +// toPounds("399p") should return "£3.99" +// toPounds("45p") should return "£0.45" +// toPounds("9p") should return "£0.09" +// toPounds("1200p") should return "£12.00" + +// The current code removes the "p", makes sur ethe number has at least 3 digits, splits pounds and pences and prints it in money format. +// Right now, it only works for "399p". I need it to work for "5p" and "1234p". +// I need to turn it into a function. eg. 'function toPounds(penceString)'. penceString clearly decribes what the input is. + +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}`; +} + +console.log(toPounds("399p")); // £3.99 +console.log(toPounds("45p")); // £0.45 +console.log(toPounds("9p")); // £0.09 +console.log(toPounds("1200p")); // £12.00 + From 5023abf7aead51d33ee7cb6c4e77700cb59e6815 Mon Sep 17 00:00:00 2001 From: Shuheda Date: Fri, 20 Feb 2026 01:07:20 +0000 Subject: [PATCH 15/26] Update time-format.js Questions answered --- Sprint-2/4-mandatory-interpret/time-format.js | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..168c441a9 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -10,25 +10,37 @@ function formatTimeDisplay(seconds) { return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } +console.log(formatTimeDisplay(61)); +//testing +//console.log(formatTimeDisplay(3661)); // 01:01:01 +//console.log(formatTimeDisplay(45)); // 00:00:45 +//console.log(formatTimeDisplay(3600)); // 01:00:00 + + // You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit // to help you answer these questions +// NOTES: +// This code converst seconds into HH:MM:SS and it uses pad() to make sure every number has 2 digits. e.g. 1 = "01". 0 = "00". +// + + // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// pad will be called 3 times. pad(totalHours), pad(remainingMinutes) and pad(remainingSeconds). // 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 +// num = 0 // c) What is the return value of pad is called for the first time? -// =============> write your answer here +// Return value = 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 +// num = 1 because 61 seconds has 1 second remaining after removing 1 minute (60 seconds). // 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" because 1 is padded to 2 digits. From bc87b24b4bd5020ea70b8d889a58de25a335b663 Mon Sep 17 00:00:00 2001 From: Shuheda Date: Fri, 20 Feb 2026 01:33:42 +0000 Subject: [PATCH 16/26] Update format-time.js Code fixed. Tested with various times. --- Sprint-2/5-stretch-extend/format-time.js | 66 ++++++++++++++++++------ 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..87d2a525b 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -2,24 +2,56 @@ // Make sure to do the prep before you do the coursework // Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. +//function formatAs12HourClock(time) { + //const hours = Number(time.slice(0, 2)); + //if (hours > 12) { + //return `${hours - 12}:00 pm`; + //} + //return `${time} am`; +//} + +//const currentOutput = formatAs12HourClock("08:00"); +//const targetOutput = "08:00 am"; +//console.assert( + //currentOutput === targetOutput, + //`current output: ${currentOutput}, target output: ${targetOutput}` +//); + +//const currentOutput2 = formatAs12HourClock("23:00"); +//const targetOutput2 = "11:00 pm"; +//console.assert( + //currentOutput2 === targetOutput2, + //`current output: ${currentOutput2}, target output: ${targetOutput2}` +//); + +// Bug 1: Minutes are hardcoded for PM. It always uses :00 for PM. If the input is "23:45", the output becomes "11:00 pm". +// Bug 2: AM hours are notconverted to 12 hour format. It works for "8:00" but "00:30" becomes "00:30" when it should be "12:30 am". +// Bug 3: 12PM and 12AM are not handled correctly. "12:00" becomes "12:00 am" whjen it should be "12:00 pm", and "00:00" becomes "00:00 am" when it should be "12:00 am". + function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); - if (hours > 12) { - return `${hours - 12}:00 pm`; + let [hours, minutes] = time.split(":"); + hours = Number(hours); + let period = "am"; + + if (hours === 0) { + hours = 12; // midnight + } else if (hours === 12) { + period = "pm"; // noon + } else if (hours > 12) { + hours -= 12; + period = "pm"; } - return `${time} am`; + + const paddedHours = hours.toString().padStart(2, "0"); + + return `${paddedHours}:${minutes} ${period}`; } -const currentOutput = formatAs12HourClock("08:00"); -const targetOutput = "08:00 am"; -console.assert( - currentOutput === targetOutput, - `current output: ${currentOutput}, target output: ${targetOutput}` -); - -const currentOutput2 = formatAs12HourClock("23:00"); -const targetOutput2 = "11:00 pm"; -console.assert( - currentOutput2 === targetOutput2, - `current output: ${currentOutput2}, target output: ${targetOutput2}` -); +//testing the function with various inputs. +console.log(formatAs12HourClock("08:00")); // 08:00 am +console.log(formatAs12HourClock("23:00")); // 11:00 pm +console.log(formatAs12HourClock("00:30")); // 12:30 am +console.log(formatAs12HourClock("12:15")); // 12:15 pm +console.log(formatAs12HourClock("13:45")); // 01:45 pm +console.log(formatAs12HourClock("11:59")); // 11:59 am +console.log(formatAs12HourClock("12:00")); // 12:00 pm From 9523989abde3f9015cbf3281d8c3feffb7866005 Mon Sep 17 00:00:00 2001 From: Shuheda Date: Wed, 25 Feb 2026 13:38:34 +0000 Subject: [PATCH 17/26] Update 1-get-angle-type.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Used the notes to write 'if' statements that reflect the requirements. e.g. "Acute angle" for angles greater than 0° and less than 90° becomes, if (angle > 0 && angle < 90) { return "Acute angle"; --- .../implement/1-get-angle-type.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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..a29683463 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 @@ -14,10 +14,24 @@ // 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 +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"; + } } + // 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; From 3ee00dd339fdae4d6a5621b8bfaa1ad0b0c7c637 Mon Sep 17 00:00:00 2001 From: Shuheda Date: Wed, 25 Feb 2026 14:09:58 +0000 Subject: [PATCH 18/26] Update 1-get-angle-type.js I wrote tests to cover all cases, including boundary and invalid. --- .../implement/1-get-angle-type.js | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) 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 a29683463..54277acf5 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 @@ -47,5 +47,54 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles + +// Acute angle test +const acute1 = getAngleType(45); +assertEquals(acute1, "Acute angle"); + +const acute2 = getAngleType(1); +assertEquals(acute2, "Acute angle"); + +const acute3 = getAngleType(89.999); +assertEquals(acute3, "Acute angle"); + +// Right angle test const right = getAngleType(90); assertEquals(right, "Right angle"); + +// Obtuse angle test +const obtuse1 = getAngleType(120); +assertEquals(obtuse1, "Obtuse angle"); + +const obtuse2 = getAngleType(179.999); +assertEquals(obtuse2, "Obtuse angle"); + +// Straight angle test +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); + +// Reflex angle test +const reflex1 = getAngleType(200); +assertEquals(reflex1, "Reflex angle"); + +const reflex2 = getAngleType(359.999); +assertEquals(reflex2, "Reflex angle"); + +// Invalid angle test +const invalid1 = getAngleType(0); +assertEquals(invalid1, "Invalid angle"); + +const invalid2 = getAngleType(360); +assertEquals(invalid2, "Invalid angle"); + +const invalid3 = getAngleType(-10); +assertEquals(invalid3, "Invalid angle"); + +const invalid4 = getAngleType(400); +assertEquals(invalid4, "Invalid angle"); + + +console.log("All tests executed."); + +// Note: If no assertion errors are thrown, all tests have passed succesfully. +// i feel there is a better way or cleaner way to write the test, but for now, this is a simple way to cover all cases. \ No newline at end of file From 4466a9b4cc6bd1b6cb0205683040f44c6a374366 Mon Sep 17 00:00:00 2001 From: Shuheda Date: Wed, 25 Feb 2026 17:19:48 +0000 Subject: [PATCH 19/26] Update 2-is-proper-fraction.js Defined proper fractions and implemented isProperFraction function. --- .../implement/2-is-proper-fraction.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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..fedc6bd9a 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 @@ -5,13 +5,27 @@ // Assumption: The parameters are valid numbers (not NaN or Infinity). // Note: If you are unfamiliar with proper fractions, please look up its mathematical definition. +// A proper fraction means: The top number (numerator) is smaller than the bottom number (denominator). +// e.g. 1/2, 3/5. 5/2 would not be a proper fraction. +// Numerator < Denominator // 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 +function isProperFraction(numerator, denominator) { + // A fraction cannot have denominator 0 + if (denominator === 0) { + return false; + } + + // A proper fraction means numerator is smaller than denominator + if (numerator < denominator) { + return true; + } else { + return false; + } } // The line below allows us to load the isProperFraction function into tests in other files. @@ -28,6 +42,8 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all cases. // What combinations of numerators and denominators should you test? +// I should test proper fractions, equal numbers, improper fractions, zero numerator, +// zero denominator and negative numbers. // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); From 9b725819db9a0a3c66e5005fb101f7c444237896 Mon Sep 17 00:00:00 2001 From: Shuheda Date: Wed, 25 Feb 2026 17:27:49 +0000 Subject: [PATCH 20/26] Update 2-is-proper-fraction.js Add comprehensive tests for isProperFraction including edge cases --- .../implement/2-is-proper-fraction.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 fedc6bd9a..06e8ec715 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 @@ -47,3 +47,23 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(3, 5), true); + +// Equal numbers (not proper) +assertEquals(isProperFraction(4, 4), false); + +// Improper fractions +assertEquals(isProperFraction(5, 2), false); +assertEquals(isProperFraction(10, 3), false); + +// Zero numerator (0 is less than denominator) +assertEquals(isProperFraction(0, 5), true); + +// Zero denominator (invalid fraction) +assertEquals(isProperFraction(5, 0), false); + +// Negative numbers +assertEquals(isProperFraction(-1, 5), true); +assertEquals(isProperFraction(1, -5), false); + +console.log("All tests executed."); \ No newline at end of file From 4e0605d546f4fc2ed81df581b31b5becf0a65882 Mon Sep 17 00:00:00 2001 From: Shuheda Date: Wed, 25 Feb 2026 20:02:59 +0000 Subject: [PATCH 21/26] Update 3-get-card-value.js Add getCardValue logic for ranks and suits. --- .../implement/3-get-card-value.js | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) 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..efa751b80 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 @@ -21,8 +21,47 @@ // After you have implemented the function, write tests to cover all the cases, and // execute the code to ensure all tests pass. +// TODO: Implement this function function getCardValue(card) { - // TODO: Implement this function + // Valid suits + const validSuits = ["♠", "♥", "♦", "♣"]; + + // Card must be at least 2 characters (e.g., "A♠") + if (typeof card !== "string" || card.length < 2) { + throw new Error("Invalid card"); + } + + // Suit is always the last character + const suit = card.slice(-1); + + // Rank is everything except the last character + const rank = card.slice(0, -1); + + // Validate suit + if (!validSuits.includes(suit)) { + throw new Error("Invalid card"); + } + + // Handle Ace + if (rank === "A") { + return 11; + } + + // Handle face cards + if (rank === "J" || rank === "Q" || rank === "K") { + return 10; + } + + // Handle number cards (2–10) + const number = Number(rank); + + if (number >= 2 && number <= 10) { + return number; + } + + // If nothing matched → invalid + throw new Error("Invalid card"); + } // The line below allows us to load the getCardValue function into tests in other files. From 4ea21491112be427f13ca36ae04c6de3fd426d19 Mon Sep 17 00:00:00 2001 From: Shuheda Date: Wed, 25 Feb 2026 20:20:06 +0000 Subject: [PATCH 22/26] Update 3-get-card-value.js Add comprehensive tests including error handling for invalid cards --- .../implement/3-get-card-value.js | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) 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 efa751b80..cabcf956b 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 @@ -77,15 +77,47 @@ function assertEquals(actualOutput, targetOutput) { } // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. +// Test: Ace, face cards, number cards, invalid suit, invalid rank, completely invalid string. // Examples: +// Number cards: assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("2♠"), 2); +assertEquals(getCardValue("10♦"), 10); + +// Face card: +assertEquals(getCardValue("J♣"), 10); +assertEquals(getCardValue("Q♦"), 10); +assertEquals(getCardValue("K♠"), 10); + +// Ace +assertEquals(getCardValue("A♥"), 11); // Handling invalid cards try { getCardValue("invalid"); + console.error("Error was not thrown for invalid string"); +} catch (e) {} + +// Invalid rank +try { + getCardValue("1♠"); + console.error("Error wasnot thrown for invalid rank"); +} catch (e) {} - // This line will not be reached if an error is thrown as expected - console.error("Error was not thrown for invalid card"); +// Invalid suit +try { + getCardValue("A?"); + console.error("Error wasnot thrown for invalid suit"); +} catch (e) {} + +// Missing suit +try { + getCardValue("A"); + console.error("Error wasnot thrown for missing suit"); } catch (e) {} +console.log("All tests executed."); + + // What other invalid card cases can you think of? +// Test: Ace, face cards, number cards, invalid suit, invalid rank, completely invalid string. \ No newline at end of file From 5c085caa6862968b367824953906b5ea04797a0a Mon Sep 17 00:00:00 2001 From: Shuheda Date: Wed, 25 Feb 2026 20:26:11 +0000 Subject: [PATCH 23/26] Update 1-get-angle-type.test.js Add comprehensive Jest tests covering all angle cases. --- .../1-get-angle-type.test.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js index d777f348d..13784416a 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js @@ -14,7 +14,33 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle +test(`should return "Right angle" when angle is 90`, () => { + expect(getAngleType(90)).toEqual("Right angle"); +}); + // Case 3: Obtuse angles +test(`should return "Obtuse angle" when (90 < angle < 180)`, () => { + expect(getAngleType(100)).toEqual("Obtuse angle"); + expect(getAngleType(150)).toEqual("Obtuse angle"); + expect(getAngleType(179)).toEqual("Obtuse angle"); +}); + // Case 4: Straight angle +test(`should return "Straight angle" when angle is 180`, () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}); + // Case 5: Reflex angles +test(`should return "Reflex angle" when (180 < angle < 360)`, () => { + expect(getAngleType(200)).toEqual("Reflex angle"); + expect(getAngleType(300)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); +}); + // Case 6: Invalid angles +test(`should return "Invalid angle" for angles outside valid range`, () => { + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(-10)).toEqual("Invalid angle"); + expect(getAngleType(400)).toEqual("Invalid angle"); +}); From 4b98073ac98e6431e6eead5aac28d9a95d93b80d Mon Sep 17 00:00:00 2001 From: Shuheda Date: Wed, 25 Feb 2026 20:31:12 +0000 Subject: [PATCH 24/26] Update 2-is-proper-fraction.test.js Add comprehensive Jest tests covering positive, negative, zero, and edge cases for isProperFraction. --- .../2-is-proper-fraction.test.js | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js index 7f087b2ba..3fd884ffd 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js @@ -5,6 +5,38 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); // TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories. // Special case: numerator is zero -test(`should return false when denominator is zero`, () => { +test(`should return false when denominator is 0`, () => { expect(isProperFraction(1, 0)).toEqual(false); + expect(isProperFraction(0, 0)).toEqual(false); }); + +// Zero numerator +test(`should return true when numerator is 0 and denominator positive`, () => { + expect(isProperFraction(0, 5)).toEqual(true); +}); + +// Proper fractions (positive) +test(`should return true for proper positive fractions`, () => { + expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(3, 5)).toEqual(true); +}); + +// Improper fractions (positive) +test(`should return false for improper positive fractions`, () => { + expect(isProperFraction(5, 2)).toEqual(false); + expect(isProperFraction(10, 3)).toEqual(false); + expect(isProperFraction(4, 4)).toEqual(false); // numerator = denominator +}); + +// Negative fractions +test(`should handle negative numerators`, () => { + expect(isProperFraction(-1, 5)).toEqual(true); +}); + +test(`should handle negative denominators`, () => { + expect(isProperFraction(1, -5)).toEqual(false); +}); + +test(`should handle both numerator and denominator negative`, () => { + expect(isProperFraction(-2, -5)).toEqual(true); +}); \ No newline at end of file From 31843b8cce3896c8d8282e91c7a6a6763070e1a4 Mon Sep 17 00:00:00 2001 From: Shuheda Date: Wed, 25 Feb 2026 20:34:29 +0000 Subject: [PATCH 25/26] Update 3-get-card-value.test.js Add Jest tests for Ace, number, face, and invalid cards for getCardValue. --- .../3-get-card-value.test.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js index cf7f9dae2..9f8e0f211 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js @@ -9,6 +9,29 @@ test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); +// Case 2: Number cards (2-10) +test(`Should return the correct number for number cards`, () => { + expect(getCardValue("2♠")).toEqual(2); + expect(getCardValue("5♥")).toEqual(5); + expect(getCardValue("10♦")).toEqual(10); +}); + +// Case 3: Face cards (J, Q, K) +test(`Should return 10 for face cards`, () => { + expect(getCardValue("J♣")).toEqual(10); + expect(getCardValue("Q♦")).toEqual(10); + expect(getCardValue("K♥")).toEqual(10); +}); + +// Case 4: Invalid cards +test(`Should throw error for invalid cards`, () => { + expect(() => getCardValue("1♠")).toThrow("Invalid card"); // invalid rank + expect(() => getCardValue("A?")).toThrow("Invalid card"); // invalid suit + expect(() => getCardValue("10♠♠")).toThrow("Invalid card"); // extra character + expect(() => getCardValue("")).toThrow("Invalid card"); // empty string + expect(() => getCardValue("banana")).toThrow("Invalid card"); // completely invalid +}); + // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) // Face Cards (J, Q, K) From ece75501e663b4607996f9154545954c12935f50 Mon Sep 17 00:00:00 2001 From: Shuheda Date: Wed, 25 Feb 2026 22:24:10 +0000 Subject: [PATCH 26/26] added sprint 2 and 3 folders --- Sprint-2/1-key-errors/0.js | 41 ------ Sprint-2/1-key-errors/1.js | 29 ----- Sprint-2/1-key-errors/2.js | 32 ----- Sprint-2/2-mandatory-debug/0.js | 24 ---- Sprint-2/2-mandatory-debug/1.js | 23 ---- Sprint-2/2-mandatory-debug/2.js | 43 ------ Sprint-2/3-mandatory-implement/1-bmi.js | 43 ------ Sprint-2/3-mandatory-implement/2-cases.js | 37 ------ Sprint-2/3-mandatory-implement/3-to-pounds.js | 62 --------- Sprint-2/4-mandatory-interpret/time-format.js | 46 ------- Sprint-2/5-stretch-extend/format-time.js | 57 -------- Sprint-2/readme.md | 41 ------ .../1-implement-and-rewrite-tests/README.md | 47 ------- .../implement/1-get-angle-type.js | 100 -------------- .../implement/2-is-proper-fraction.js | 69 ---------- .../implement/3-get-card-value.js | 123 ------------------ .../1-get-angle-type.test.js | 46 ------- .../2-is-proper-fraction.test.js | 42 ------ .../3-get-card-value.test.js | 43 ------ .../testing-guide.md | 92 ------------- Sprint-3/2-practice-tdd/README.md | 13 -- Sprint-3/2-practice-tdd/count.js | 5 - Sprint-3/2-practice-tdd/count.test.js | 24 ---- Sprint-3/2-practice-tdd/get-ordinal-number.js | 5 - .../2-practice-tdd/get-ordinal-number.test.js | 20 --- Sprint-3/2-practice-tdd/repeat-str.js | 5 - Sprint-3/2-practice-tdd/repeat-str.test.js | 32 ----- Sprint-3/3-dead-code/README.md | 9 -- Sprint-3/3-dead-code/exercise-1.js | 17 --- Sprint-3/3-dead-code/exercise-2.js | 28 ---- Sprint-3/4-stretch/README.md | 9 -- Sprint-3/4-stretch/card-validator.md | 35 ----- Sprint-3/4-stretch/find.js | 25 ---- Sprint-3/4-stretch/password-validator.js | 6 - Sprint-3/4-stretch/password-validator.test.js | 26 ---- Sprint-3/readme.md | 18 --- 36 files changed, 1317 deletions(-) delete mode 100644 Sprint-2/1-key-errors/0.js delete mode 100644 Sprint-2/1-key-errors/1.js delete mode 100644 Sprint-2/1-key-errors/2.js delete mode 100644 Sprint-2/2-mandatory-debug/0.js delete mode 100644 Sprint-2/2-mandatory-debug/1.js delete mode 100644 Sprint-2/2-mandatory-debug/2.js delete mode 100644 Sprint-2/3-mandatory-implement/1-bmi.js delete mode 100644 Sprint-2/3-mandatory-implement/2-cases.js delete mode 100644 Sprint-2/3-mandatory-implement/3-to-pounds.js delete mode 100644 Sprint-2/4-mandatory-interpret/time-format.js delete mode 100644 Sprint-2/5-stretch-extend/format-time.js delete mode 100644 Sprint-2/readme.md delete mode 100644 Sprint-3/1-implement-and-rewrite-tests/README.md delete mode 100644 Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js delete mode 100644 Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js delete mode 100644 Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js delete mode 100644 Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js delete mode 100644 Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js delete mode 100644 Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js delete mode 100644 Sprint-3/1-implement-and-rewrite-tests/testing-guide.md delete mode 100644 Sprint-3/2-practice-tdd/README.md delete mode 100644 Sprint-3/2-practice-tdd/count.js delete mode 100644 Sprint-3/2-practice-tdd/count.test.js delete mode 100644 Sprint-3/2-practice-tdd/get-ordinal-number.js delete mode 100644 Sprint-3/2-practice-tdd/get-ordinal-number.test.js delete mode 100644 Sprint-3/2-practice-tdd/repeat-str.js delete mode 100644 Sprint-3/2-practice-tdd/repeat-str.test.js delete mode 100644 Sprint-3/3-dead-code/README.md delete mode 100644 Sprint-3/3-dead-code/exercise-1.js delete mode 100644 Sprint-3/3-dead-code/exercise-2.js delete mode 100644 Sprint-3/4-stretch/README.md delete mode 100644 Sprint-3/4-stretch/card-validator.md delete mode 100644 Sprint-3/4-stretch/find.js delete mode 100644 Sprint-3/4-stretch/password-validator.js delete mode 100644 Sprint-3/4-stretch/password-validator.test.js delete mode 100644 Sprint-3/readme.md diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js deleted file mode 100644 index 434814849..000000000 --- a/Sprint-2/1-key-errors/0.js +++ /dev/null @@ -1,41 +0,0 @@ -// Predict and explain first... -// I predict when this code runs, there will be a SyntaxError before the function executes. -// This is because the identifier 'str' has already been declared. - -// call the function capitalise with a string input -// capitalise("hello"); - - -// interpret the error message and figure out why an error is occurring -// Uncaught SyntaxError: Unexpected identifier 'string' - this is the error message. -// This error is occuring because the variable 'str' is being redeclared within the function, which is not allowed in JavaScript. -// The duplicate use if 'str' is causing the syntax error. - - -//function capitalise(str) { - //let str = `${str[0].toUpperCase()}${str.slice(1)}`; - //return str; -//} - -// The issue is variable redeclaration. -// str is the function parameter. -// let str tries to create a new variable with the same name. -// JavaScript does not allow redeclaring a variable in the same scope. -// As a result, the code throws a SyntaxError when it encounters the second 'str' declaration. - -// New code without the error: - -// 0.js — fully fixed version -function capitalise(str) { - if (!str) return str; // handles empty string - return str[0].toUpperCase() + str.slice(1); -} - -// Test it -console.log(capitalise("hello")); // should print "Hello" -console.log(capitalise("world")); // should print "World" -console.log(capitalise("")); // should print "" - - - - diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js deleted file mode 100644 index 1c0cbb33c..000000000 --- a/Sprint-2/1-key-errors/1.js +++ /dev/null @@ -1,29 +0,0 @@ -// Predict and explain first... -// Why will an error occur when this program runs? -// I predict an error will occur when this program runs because the variable 'decimalNumber' is already declared inside the function 'convertToPercentage' and cannot be redeclared. - -// Try playing computer with the example to work out what is going on -// When the 'function convertToPercentage(decimalNumber)' is created, Javascript already creates a variable called decimalNumber. then, inside the function, 'const decimalNumber = 0.5' tries to create another variable with the same name. This casues a syntax error because you cannot declare two variables with the same name in the same scope. - -// function convertToPercentage(decimalNumber) { - // const decimalNumber = 0.5; - // const percentage = `${decimalNumber * 100}%`; - - // return percentage; -// } - -// console.log(decimalNumber); - -// Write your explanation here -// I redelcared the parameter decimalNumber using const. -// I tried to log decimalNumber outside its scope. -// The variables declared inside the function are not available outside unless they are returned. - -// Finally, correct the code to fix the problem - -function convertToPercentage(decimalNumber) { - const percentage = `${decimalNumber * 100}%`; - return percentage; -} - -console.log(convertToPercentage(0.5)); // "50%" diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js deleted file mode 100644 index a6183a5c6..000000000 --- a/Sprint-2/1-key-errors/2.js +++ /dev/null @@ -1,32 +0,0 @@ - -// Predict and explain first BEFORE you run any code... -// This function should square any number but instead we're going to get an error - -// Write your prediction of the error here: -// I predict that the error will be a syntax error because the parameter '3' is not a valid variable name. -// When you define a function,, the thing inside the parentahese must be a parameter name, NOT a number. - -// function square(3) { - // return num * num; -// } - -// Write the error message here -// SyntaxError: Unexpected number - -// Explain the error messge here: -// When defining a function, inside the parentheses, you need to put a parameter name, which is a variable. -// In this case, '3' is not a valid parameter name because it is a number, not a variable. -// This causes a syntax error because Javascript expects a name, not a number. - -// Finally, correct the code to fix the problem -// Write your new code here - -function square(num) { - return num * num; -} - -console.log(square(3)); // 9 -console.log(square(5)); // 25 - - - diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js deleted file mode 100644 index 51ce1ba85..000000000 --- a/Sprint-2/2-mandatory-debug/0.js +++ /dev/null @@ -1,24 +0,0 @@ -// Predict and explain first...write your prediction here -// I predict, when the code runs, it will print 320, but it will also print "The result of multiplying 10 and 32 is undefined". - -//function multiply(a, b) { -// console.log(a * b); -// } - -// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); - -// Write your explanation here -// The function multiply(a, b) logs the result of a * b to the console but does not return a value. -// When multiply(10, 32) is called within the template literal, it logs 320 to the console but returns undefined. -// Therefore, inside the template literal, the value is undefined, which is why the final output becomes "The result of multiplying 10 and 32 is undefined". - -// Finally, correct the code to fix the problem -// Write your new code here -// To fix the problem, the function should return the result instead of logging it. - -function multiply(a, b) { - return a * b; -} - -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); - diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js deleted file mode 100644 index 97b068aba..000000000 --- a/Sprint-2/2-mandatory-debug/1.js +++ /dev/null @@ -1,23 +0,0 @@ -// Predict and explain first...write your prediction here -// I think the code will return undefined. - -//function sum(a, b) { - // return; - // a + b; -//} - -//console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); - -// Write your explanation here -// When JavaScript sees the 'return' statement, it immediately stopd the function. It does NOT continue to the next line. -// So this part, 'a+b;' never runs. To return the sum of a and b, we need to put it on the same line as the return. -// Like the: 'return a + b;' - -// 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 deleted file mode 100644 index 1819a950d..000000000 --- a/Sprint-2/2-mandatory-debug/2.js +++ /dev/null @@ -1,43 +0,0 @@ -// Predict and explain first... - -// Predict the output of the following code: -// Write your prediction here -// I think the output will be 'The last digit of 42 is 2', 'The last digit of 105 is 5', and 'The last digit of 806 is 6'. -// I think this will happen because the getLastDigit function is supposed to take a number, convert it to a string, and then return the last charecter of that string, which should be the last digit. - -//const num = 103; - -//function getLastDigit() { -// return num.toString().slice(-1); -//} - -//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)}`); - -// Now run the code and compare the output to your prediction -// Write the output here -// The output is: -// 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 output is 3 for all numbers because the function getLastDigit is not taking any parameters. It always uses the global variable `num` which is set to 103. So it always returns the last digit of 103, which is 3. - -// Finally, correct the code to fix the problem -// Write your new code here - -function getLastDigit(number) { - return number.toString().slice(-1); -} - -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 did not accept a parameter. It was a fixed variable (num = 103), so it always returned the last digit of 103. \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js deleted file mode 100644 index c2b35cc71..000000000 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ /dev/null @@ -1,43 +0,0 @@ -// Below are the steps for how BMI is calculated - -// The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared. - -// For example, if you weigh 70kg (around 11 stone) and are 1.73m (around 5 feet 8 inches) tall, you work out your BMI by: - -// squaring your height: 1.73 x 1.73 = 2.99 -// dividing 70 by 2.99 = 23.41 -// Your result will be displayed to 1 decimal place, for example 23.4. - -// You will need to implement a function that calculates the BMI of someone based off their weight and height - -// Given someone's weight in kg and height in metres -// Then when we call this function with the weight and height -// It should return their Body Mass Index to 1 decimal place - -//function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height -// } - -// Notes: -// BMI = weight ÷ (height x height) -// eg. BMI = 70kg ÷ (1.73m x 1.73) -// BMI = 70kg ÷ 2.99 -// BMI = 23.41 -// BMI = 23.4 (to 1 decimal place) - -// I need to: -// 1. Square the height -// 2. Divide weight by squared height -// 3. Round the result to 1 decimal place -// 4. Return the result - -function calculateBMI(weight, height) { - const bmi = weight / (height * height); - return bmi.toFixed(1); -} - -console.log(calculateBMI(70, 1.73)); - - - -//toFixed(1) tells JavaScript to round the number to 1 decimal place. \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js deleted file mode 100644 index 180b793b5..000000000 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ /dev/null @@ -1,37 +0,0 @@ -// A set of words can be grouped together in different cases. - -// For example, "hello there" in snake case would be written "hello_there" -// UPPER_SNAKE_CASE means taking a string and writing it in all caps with underscores instead of spaces. - -// Implement a function that: - -// Given a string input like "hello there" -// When we call this function with the input string -// it returns the string in UPPER_SNAKE_CASE, so "HELLO_THERE" - -// Another example: "lord of the rings" should be "LORD_OF_THE_RINGS" - -// 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 - -// NOTES: -// "hello there" should become "HELLO_THERE" -// I need to turn all letters into CAPITALS and replace the space " " with underscore "-" - -// From the MDN documentation: -// I can use the toUpperCase() to turn the tring into all CAPS. -// I can use the replaceAll() to replace all the spaces with underscores. - -// Good function name: -// toUpperSnakeCase - this name is decriptive and indicates that the function will convert a string to upper snake case. - -function toUpperSnakeCase(str) { - return str.toUpperCase().replaceAll(" ", "_"); -} - -console.log(toUpperSnakeCase("hello there")); -// HELLO_THERE - -console.log(toUpperSnakeCase("lord of the rings")); -// LORD_OF_THE_RINGS diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js deleted file mode 100644 index 88942684e..000000000 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ /dev/null @@ -1,62 +0,0 @@ -// In Sprint-1, there is a program written in interpret/to-pounds.js - -// ORIGINAL CODE: -//const penceString = "399p"; - -//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"); - -//console.log(`£${pounds}.${pence}`); - - -// You will need to take this code and turn it into a reusable block of code. -// 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. -// For example: -// toPounds("399p") should return "£3.99" -// toPounds("45p") should return "£0.45" -// toPounds("9p") should return "£0.09" -// toPounds("1200p") should return "£12.00" - -// The current code removes the "p", makes sur ethe number has at least 3 digits, splits pounds and pences and prints it in money format. -// Right now, it only works for "399p". I need it to work for "5p" and "1234p". -// I need to turn it into a function. eg. 'function toPounds(penceString)'. penceString clearly decribes what the input is. - -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}`; -} - -console.log(toPounds("399p")); // £3.99 -console.log(toPounds("45p")); // £0.45 -console.log(toPounds("9p")); // £0.09 -console.log(toPounds("1200p")); // £12.00 - diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js deleted file mode 100644 index 168c441a9..000000000 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ /dev/null @@ -1,46 +0,0 @@ -function pad(num) { - return num.toString().padStart(2, "0"); -} - -function formatTimeDisplay(seconds) { - const remainingSeconds = seconds % 60; - const totalMinutes = (seconds - remainingSeconds) / 60; - const remainingMinutes = totalMinutes % 60; - const totalHours = (totalMinutes - remainingMinutes) / 60; - - return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; -} -console.log(formatTimeDisplay(61)); -//testing -//console.log(formatTimeDisplay(3661)); // 01:01:01 -//console.log(formatTimeDisplay(45)); // 00:00:45 -//console.log(formatTimeDisplay(3600)); // 01:00:00 - - - -// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit -// to help you answer these questions - -// NOTES: -// This code converst seconds into HH:MM:SS and it uses pad() to make sure every number has 2 digits. e.g. 1 = "01". 0 = "00". -// - - -// Questions - -// a) When formatTimeDisplay is called how many times will pad be called? -// pad will be called 3 times. pad(totalHours), pad(remainingMinutes) and pad(remainingSeconds). - -// 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? -// num = 0 - -// c) What is the return value of pad is called for the first time? -// Return value = 00. - -// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer -// num = 1 because 61 seconds has 1 second remaining after removing 1 minute (60 seconds). - -// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer -// "01" because 1 is padded to 2 digits. diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js deleted file mode 100644 index 87d2a525b..000000000 --- a/Sprint-2/5-stretch-extend/format-time.js +++ /dev/null @@ -1,57 +0,0 @@ -// This is the latest solution to the problem from the prep. -// Make sure to do the prep before you do the coursework -// Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. - -//function formatAs12HourClock(time) { - //const hours = Number(time.slice(0, 2)); - //if (hours > 12) { - //return `${hours - 12}:00 pm`; - //} - //return `${time} am`; -//} - -//const currentOutput = formatAs12HourClock("08:00"); -//const targetOutput = "08:00 am"; -//console.assert( - //currentOutput === targetOutput, - //`current output: ${currentOutput}, target output: ${targetOutput}` -//); - -//const currentOutput2 = formatAs12HourClock("23:00"); -//const targetOutput2 = "11:00 pm"; -//console.assert( - //currentOutput2 === targetOutput2, - //`current output: ${currentOutput2}, target output: ${targetOutput2}` -//); - -// Bug 1: Minutes are hardcoded for PM. It always uses :00 for PM. If the input is "23:45", the output becomes "11:00 pm". -// Bug 2: AM hours are notconverted to 12 hour format. It works for "8:00" but "00:30" becomes "00:30" when it should be "12:30 am". -// Bug 3: 12PM and 12AM are not handled correctly. "12:00" becomes "12:00 am" whjen it should be "12:00 pm", and "00:00" becomes "00:00 am" when it should be "12:00 am". - -function formatAs12HourClock(time) { - let [hours, minutes] = time.split(":"); - hours = Number(hours); - let period = "am"; - - if (hours === 0) { - hours = 12; // midnight - } else if (hours === 12) { - period = "pm"; // noon - } else if (hours > 12) { - hours -= 12; - period = "pm"; - } - - const paddedHours = hours.toString().padStart(2, "0"); - - return `${paddedHours}:${minutes} ${period}`; -} - -//testing the function with various inputs. -console.log(formatAs12HourClock("08:00")); // 08:00 am -console.log(formatAs12HourClock("23:00")); // 11:00 pm -console.log(formatAs12HourClock("00:30")); // 12:30 am -console.log(formatAs12HourClock("12:15")); // 12:15 pm -console.log(formatAs12HourClock("13:45")); // 01:45 pm -console.log(formatAs12HourClock("11:59")); // 11:59 am -console.log(formatAs12HourClock("12:00")); // 12:00 pm diff --git a/Sprint-2/readme.md b/Sprint-2/readme.md deleted file mode 100644 index 44c118e33..000000000 --- a/Sprint-2/readme.md +++ /dev/null @@ -1,41 +0,0 @@ -# 🧭 Guide to week 2 exercises - -> https://programming.codeyourfuture.io/structuring-data/sprints/2/prep/ - -> [!TIP] -> You should always do the prep work _before_ attempting the coursework. -> The prep shows you how to do the coursework. -> There is often a step by step video you can code along with too. -> Do the prep. - -## 1 Errors - -In this section, you need to go to each file in `errors` directory. Read the file and predict what error will happen. Then run the file with node to check what the error is. Your task is to interpret the error message and explain why it occurs. The [errors documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors) will help you figure out the solution. - -## 2 Debug - -In this section, you need to go to each file in `debug` to **explain and predict** why the program isn't behaving as intended. Then you'll need to run the program with node to check your prediction. You will also need to correct the code too. - -## 3 Implement - -In this section, you will have a short set of requirements about a function. You will need to implement a function based off this set of requirements. Make sure you check your function works for a number of different inputs. - -Here is a recommended order: - -1. `1-bmi.js` -1. `2-cases.js` -1. `3-to-pounds.js` - -## 4 Interpret - -In these tasks, you have to interpret a slightly larger program with some syntax / operators / functions that may be unfamiliar. - -You must use documentation to make sense of anything unfamiliar. Learning how to look things up this way is a fundamental part of being a developer! - -You can also use `console.log` to check the value of different variables in the code. - -## 5 Extend - -In the prep for this sprint, we developed a function to convert 24 hour clock times to 12 hour clock times. - -Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. This section is not mandatory, but it will also help you solve some similar kata in Codewars. diff --git a/Sprint-3/1-implement-and-rewrite-tests/README.md b/Sprint-3/1-implement-and-rewrite-tests/README.md deleted file mode 100644 index a65bd2077..000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# Implement solutions and rewrite tests with Jest - -Before writing any code, please read the [Testing Function Guide](testing-guide.md) to learn how -to choose test values that thoroughly test a function. - -## 1 Implement solutions - -In the `implement` directory you've got a number of functions you'll need to implement. -For each function, you also have a number of different cases you'll need to check for your function. - -Write your assertions and build up your program case by case. Don't rush to a solution. The point of these assignments is to learn how to write assertions and build up a program step by step. - -Here is a recommended order: - -1. `1-get-angle-type.js` -2. `2-is-proper-fraction.js` -3. `3-get-card-value.js` - -## 2 Rewrite tests with Jest - -`console.log` is most often used as a debugging tool. We use to inspect the state of our program during runtime. - -We can use `console.assert` to write assertions: however, it is not very easy to use when writing large test suites. In the first section, Implement, we used a custom "helper function" to make our assertions more readable. - -Jest is a whole library of helper functions we can use to make our assertions more readable and easier to write. - -Your new task is to write the same tests as you wrote in the `implement` directory, but using Jest instead of `console.assert`. - -You shouldn't have to change the contents of `implement` to write these tests. - -There are files for your Jest tests in the `rewrite-tests-with-jest` directory. They will automatically use the functions you already implemented. - -You can run all the tests in this repo by running `npm test` in your terminal. However, VSCode has a built-in test runner that you can use to run the tests, and this should make it much easier to focus on building up your test cases one at a time. - -https://code.visualstudio.com/docs/editor/testing - -1. Go to rewrite-tests-with-jest/1-get-angle-type.test.js -2. Click the green play button to run the test. It's on the left of the test function in the gutter. -3. Read the output in the TEST_RESULTS tab at the bottom of the screen. -4. Explore all the tests in this repo by opening the TEST EXPLORER tab. The logo is a beaker. - -![VSCode Test Runner](../../run-this-test.png) - -![Test Results](../../test-results-output.png) - -> [!TIP] -> You can always run a single test file by running `npm test path/to/test-file.test.js`. 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 deleted file mode 100644 index 54277acf5..000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ /dev/null @@ -1,100 +0,0 @@ -// Implement a function getAngleType -// -// When given an angle in degrees, it should return a string indicating the type of angle: -// - "Acute angle" for angles greater than 0° and less than 90° -// - "Right angle" for exactly 90° -// - "Obtuse angle" for angles greater than 90° and less than 180° -// - "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. - - // TODO: Implement this function -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"; - } -} - - -// 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 - -// Acute angle test -const acute1 = getAngleType(45); -assertEquals(acute1, "Acute angle"); - -const acute2 = getAngleType(1); -assertEquals(acute2, "Acute angle"); - -const acute3 = getAngleType(89.999); -assertEquals(acute3, "Acute angle"); - -// Right angle test -const right = getAngleType(90); -assertEquals(right, "Right angle"); - -// Obtuse angle test -const obtuse1 = getAngleType(120); -assertEquals(obtuse1, "Obtuse angle"); - -const obtuse2 = getAngleType(179.999); -assertEquals(obtuse2, "Obtuse angle"); - -// Straight angle test -const straight = getAngleType(180); -assertEquals(straight, "Straight angle"); - -// Reflex angle test -const reflex1 = getAngleType(200); -assertEquals(reflex1, "Reflex angle"); - -const reflex2 = getAngleType(359.999); -assertEquals(reflex2, "Reflex angle"); - -// Invalid angle test -const invalid1 = getAngleType(0); -assertEquals(invalid1, "Invalid angle"); - -const invalid2 = getAngleType(360); -assertEquals(invalid2, "Invalid angle"); - -const invalid3 = getAngleType(-10); -assertEquals(invalid3, "Invalid angle"); - -const invalid4 = getAngleType(400); -assertEquals(invalid4, "Invalid angle"); - - -console.log("All tests executed."); - -// Note: If no assertion errors are thrown, all tests have passed succesfully. -// i feel there is a better way or cleaner way to write the test, but for now, this is a simple way to cover all cases. \ 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 deleted file mode 100644 index 06e8ec715..000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ /dev/null @@ -1,69 +0,0 @@ -// Implement a function isProperFraction, -// when given two numbers, a numerator and a denominator, it should return true if -// the given numbers form a proper fraction, and false otherwise. - -// Assumption: The parameters are valid numbers (not NaN or Infinity). - -// Note: If you are unfamiliar with proper fractions, please look up its mathematical definition. -// A proper fraction means: The top number (numerator) is smaller than the bottom number (denominator). -// e.g. 1/2, 3/5. 5/2 would not be a proper fraction. -// Numerator < Denominator - -// Acceptance criteria: -// After you have implemented the function, write tests to cover all the cases, and -// execute the code to ensure all tests pass. - - // TODO: Implement this function -function isProperFraction(numerator, denominator) { - // A fraction cannot have denominator 0 - if (denominator === 0) { - return false; - } - - // A proper fraction means numerator is smaller than denominator - if (numerator < denominator) { - return true; - } else { - 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}` - ); -} - -// TODO: Write tests to cover all cases. -// What combinations of numerators and denominators should you test? -// I should test proper fractions, equal numbers, improper fractions, zero numerator, -// zero denominator and negative numbers. - -// Example: 1/2 is a proper fraction -assertEquals(isProperFraction(1, 2), true); -assertEquals(isProperFraction(3, 5), true); - -// Equal numbers (not proper) -assertEquals(isProperFraction(4, 4), false); - -// Improper fractions -assertEquals(isProperFraction(5, 2), false); -assertEquals(isProperFraction(10, 3), false); - -// Zero numerator (0 is less than denominator) -assertEquals(isProperFraction(0, 5), true); - -// Zero denominator (invalid fraction) -assertEquals(isProperFraction(5, 0), false); - -// Negative numbers -assertEquals(isProperFraction(-1, 5), true); -assertEquals(isProperFraction(1, -5), false); - -console.log("All tests executed."); \ 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 deleted file mode 100644 index cabcf956b..000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ /dev/null @@ -1,123 +0,0 @@ -// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck - -// Implement a function getCardValue, when given a string representing a playing card, -// should return the numerical value of the card. - -// A valid card string will contain a rank followed by the suit. -// The rank can be one of the following strings: -// "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" -// The suit can be one of the following emojis: -// "♠", "♥", "♦", "♣" -// For example: "A♠", "2♥", "10♥", "J♣", "Q♦", "K♦". - -// When the card is an ace ("A"), the function should return 11. -// When the card is a face card ("J", "Q", "K"), the function should return 10. -// When the card is a number card ("2" to "10"), the function should return its numeric value. - -// When the card string is invalid (not following the above format), the function should -// throw an error. - -// Acceptance criteria: -// After you have implemented the function, write tests to cover all the cases, and -// execute the code to ensure all tests pass. - -// TODO: Implement this function -function getCardValue(card) { - // Valid suits - const validSuits = ["♠", "♥", "♦", "♣"]; - - // Card must be at least 2 characters (e.g., "A♠") - if (typeof card !== "string" || card.length < 2) { - throw new Error("Invalid card"); - } - - // Suit is always the last character - const suit = card.slice(-1); - - // Rank is everything except the last character - const rank = card.slice(0, -1); - - // Validate suit - if (!validSuits.includes(suit)) { - throw new Error("Invalid card"); - } - - // Handle Ace - if (rank === "A") { - return 11; - } - - // Handle face cards - if (rank === "J" || rank === "Q" || rank === "K") { - return 10; - } - - // Handle number cards (2–10) - const number = Number(rank); - - if (number >= 2 && number <= 10) { - return number; - } - - // If nothing matched → invalid - throw new Error("Invalid card"); - -} - -// 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; - -// Helper functions to make our assertions easier to read. -function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); -} - -// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. -// Test: Ace, face cards, number cards, invalid suit, invalid rank, completely invalid string. -// Examples: -// Number cards: -assertEquals(getCardValue("9♠"), 9); -assertEquals(getCardValue("2♠"), 2); -assertEquals(getCardValue("10♦"), 10); - -// Face card: -assertEquals(getCardValue("J♣"), 10); -assertEquals(getCardValue("Q♦"), 10); -assertEquals(getCardValue("K♠"), 10); - -// Ace -assertEquals(getCardValue("A♥"), 11); - -// Handling invalid cards -try { - getCardValue("invalid"); - console.error("Error was not thrown for invalid string"); -} catch (e) {} - -// Invalid rank -try { - getCardValue("1♠"); - console.error("Error wasnot thrown for invalid rank"); -} catch (e) {} - -// Invalid suit -try { - getCardValue("A?"); - console.error("Error wasnot thrown for invalid suit"); -} catch (e) {} - -// Missing suit -try { - getCardValue("A"); - console.error("Error wasnot thrown for missing suit"); -} catch (e) {} - -console.log("All tests executed."); - - -// What other invalid card cases can you think of? -// Test: Ace, face cards, number cards, invalid suit, invalid rank, completely invalid string. \ No newline at end of file diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js deleted file mode 100644 index 13784416a..000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js +++ /dev/null @@ -1,46 +0,0 @@ -// This statement loads the getAngleType function you wrote in the implement directory. -// We will use the same function, but write tests for it using Jest in this file. -const getAngleType = require("../implement/1-get-angle-type"); - -// TODO: Write tests in Jest syntax to cover all cases/outcomes, -// including boundary and invalid cases. - -// Case 1: Acute angles -test(`should return "Acute angle" when (0 < angle < 90)`, () => { - // Test various acute angles, including boundary cases - expect(getAngleType(1)).toEqual("Acute angle"); - expect(getAngleType(45)).toEqual("Acute angle"); - expect(getAngleType(89)).toEqual("Acute angle"); -}); - -// Case 2: Right angle -test(`should return "Right angle" when angle is 90`, () => { - expect(getAngleType(90)).toEqual("Right angle"); -}); - -// Case 3: Obtuse angles -test(`should return "Obtuse angle" when (90 < angle < 180)`, () => { - expect(getAngleType(100)).toEqual("Obtuse angle"); - expect(getAngleType(150)).toEqual("Obtuse angle"); - expect(getAngleType(179)).toEqual("Obtuse angle"); -}); - -// Case 4: Straight angle -test(`should return "Straight angle" when angle is 180`, () => { - expect(getAngleType(180)).toEqual("Straight angle"); -}); - -// Case 5: Reflex angles -test(`should return "Reflex angle" when (180 < angle < 360)`, () => { - expect(getAngleType(200)).toEqual("Reflex angle"); - expect(getAngleType(300)).toEqual("Reflex angle"); - expect(getAngleType(359)).toEqual("Reflex angle"); -}); - -// Case 6: Invalid angles -test(`should return "Invalid angle" for angles outside valid range`, () => { - expect(getAngleType(0)).toEqual("Invalid angle"); - expect(getAngleType(360)).toEqual("Invalid angle"); - expect(getAngleType(-10)).toEqual("Invalid angle"); - expect(getAngleType(400)).toEqual("Invalid angle"); -}); diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js deleted file mode 100644 index 3fd884ffd..000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ /dev/null @@ -1,42 +0,0 @@ -// This statement loads the isProperFraction function you wrote in the implement directory. -// We will use the same function, but write tests for it using Jest in this file. -const isProperFraction = require("../implement/2-is-proper-fraction"); - -// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories. - -// Special case: numerator is zero -test(`should return false when denominator is 0`, () => { - expect(isProperFraction(1, 0)).toEqual(false); - expect(isProperFraction(0, 0)).toEqual(false); -}); - -// Zero numerator -test(`should return true when numerator is 0 and denominator positive`, () => { - expect(isProperFraction(0, 5)).toEqual(true); -}); - -// Proper fractions (positive) -test(`should return true for proper positive fractions`, () => { - expect(isProperFraction(1, 2)).toEqual(true); - expect(isProperFraction(3, 5)).toEqual(true); -}); - -// Improper fractions (positive) -test(`should return false for improper positive fractions`, () => { - expect(isProperFraction(5, 2)).toEqual(false); - expect(isProperFraction(10, 3)).toEqual(false); - expect(isProperFraction(4, 4)).toEqual(false); // numerator = denominator -}); - -// Negative fractions -test(`should handle negative numerators`, () => { - expect(isProperFraction(-1, 5)).toEqual(true); -}); - -test(`should handle negative denominators`, () => { - expect(isProperFraction(1, -5)).toEqual(false); -}); - -test(`should handle both numerator and denominator negative`, () => { - expect(isProperFraction(-2, -5)).toEqual(true); -}); \ No newline at end of file diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js deleted file mode 100644 index 9f8e0f211..000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ /dev/null @@ -1,43 +0,0 @@ -// This statement loads the getCardValue function you wrote in the implement directory. -// We will use the same function, but write tests for it using Jest in this file. -const getCardValue = require("../implement/3-get-card-value"); - -// TODO: Write tests in Jest syntax to cover all possible outcomes. - -// Case 1: Ace (A) -test(`Should return 11 when given an ace card`, () => { - expect(getCardValue("A♠")).toEqual(11); -}); - -// Case 2: Number cards (2-10) -test(`Should return the correct number for number cards`, () => { - expect(getCardValue("2♠")).toEqual(2); - expect(getCardValue("5♥")).toEqual(5); - expect(getCardValue("10♦")).toEqual(10); -}); - -// Case 3: Face cards (J, Q, K) -test(`Should return 10 for face cards`, () => { - expect(getCardValue("J♣")).toEqual(10); - expect(getCardValue("Q♦")).toEqual(10); - expect(getCardValue("K♥")).toEqual(10); -}); - -// Case 4: Invalid cards -test(`Should throw error for invalid cards`, () => { - expect(() => getCardValue("1♠")).toThrow("Invalid card"); // invalid rank - expect(() => getCardValue("A?")).toThrow("Invalid card"); // invalid suit - expect(() => getCardValue("10♠♠")).toThrow("Invalid card"); // extra character - expect(() => getCardValue("")).toThrow("Invalid card"); // empty string - expect(() => getCardValue("banana")).toThrow("Invalid card"); // completely invalid -}); - -// Suggestion: Group the remaining test data into these categories: -// Number Cards (2-10) -// Face Cards (J, Q, K) -// Invalid Cards - -// To learn how to test whether a function throws an error as expected in Jest, -// please refer to the Jest documentation: -// https://jestjs.io/docs/expect#tothrowerror - diff --git a/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md b/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md deleted file mode 100644 index 917194e7a..000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md +++ /dev/null @@ -1,92 +0,0 @@ -# A Beginner's Guide to Testing Functions - -## 1. What Is a Function? - -``` -Input ──▶ Function ──▶ Output -``` - -A function -- Takes **input** (via **arguments**) -- Does some work -- Produces **one output** (via a **return value**) - -Example: - -``` -sum(2, 3) → 5 -``` - -Important idea: the same input should produce the same output. - - -## 2. Testing Means Predicting - -Testing means: -> If I give this input, what output should I get? - - -## 3. Choosing Good Test Values - -### Step 1: Determining the space of possible inputs -Ask: -- What type of value is expected? -- What values make sense? - - If they are numbers: - - Are they integers or floating-point numbers? - - What is their range? - - If they are strings: - - What are their length and patterns? -- What values would not make sense? - -### Step 2: Choosing Good Test Values - -#### Normal Cases - -These confirm that the function works in normal use. - -- What does a typical, ordinary input look like? -- Are there multiple ordinary groups of inputs? e.g. for an age checking function, maybe there are "adults" and "children" as expected ordinary groups of inputs. - - -#### Boundary Cases - -Test values exactly at, just inside, and just outside defined ranges. -These values are where logic breaks most often. - -#### Consider All Outcomes - -Every outcome must be reached by at least one test. - -- How many different results can this function produce? -- Have I tested a value that leads to each one? - -#### Crossing the Edges and Invalid Values - -This tests how the function behaves when assumptions are violated. -- What happens when input is outside of the expected range? -- What happens when input is not of the expected type? -- What happens when input is not in the expected format? - -## 4. How to Test - -### 1. Using `console.assert()` - -```javascript - // Report a failure only when the first argument is false - console.assert( sum(4, 6) === 10, "Expected 4 + 6 to equal 10" ); -``` - -It is simpler than using `if-else` and requires no setup. - -### 2. Jest Testing Framework - -```javascript - test("Should correctly return the sum of two positive numbers", () => { - expect( sum(4, 6) ).toEqual(10); - ... // Can test multiple samples - }); - -``` - -Jest supports many useful functions for testing but requires additional setup. diff --git a/Sprint-3/2-practice-tdd/README.md b/Sprint-3/2-practice-tdd/README.md deleted file mode 100644 index f7d82fe43..000000000 --- a/Sprint-3/2-practice-tdd/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Practice TDD - -In this section you'll practice this key skill of building up your program test first. - -Use the Jest syntax and complete the provided files, meeting the acceptance criteria for each function. Use the VSCode test runner to run your tests and check your progress. - -Write the tests _before_ the code that will make them pass. - -Recommended order: - -1. `count.test.js` -1. `repeat-str.test.js` -1. `get-ordinal-number.test.js` diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js deleted file mode 100644 index 95b6ebb7d..000000000 --- a/Sprint-3/2-practice-tdd/count.js +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index 179ea0ddf..000000000 --- a/Sprint-3/2-practice-tdd/count.test.js +++ /dev/null @@ -1,24 +0,0 @@ -// 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: - -// 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"; - 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`. -// When the function is called with these inputs, -// Then it should return 0, indicating that no occurrences of `char` were found. diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js deleted file mode 100644 index f95d71db1..000000000 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ /dev/null @@ -1,5 +0,0 @@ -function getOrdinalNumber(num) { - return "1st"; -} - -module.exports = getOrdinalNumber; diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js deleted file mode 100644 index adfa58560..000000000 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ /dev/null @@ -1,20 +0,0 @@ -const getOrdinalNumber = require("./get-ordinal-number"); -// In this week's prep, we started implementing getOrdinalNumber. - -// Continue testing and implementing getOrdinalNumber for additional cases. -// Write your tests using Jest — remember to run your tests often for continual feedback. - -// To ensure thorough testing, we need broad scenarios that cover all possible cases. -// Listing individual values, however, can quickly lead to an unmanageable number of test cases. -// 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 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(21)).toEqual("21st"); - expect(getOrdinalNumber(131)).toEqual("131st"); -}); diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js deleted file mode 100644 index 3838c7b00..000000000 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ /dev/null @@ -1,5 +0,0 @@ -function repeatStr() { - return "hellohellohello"; -} - -module.exports = repeatStr; diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js deleted file mode 100644 index a3fc1196c..000000000 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ /dev/null @@ -1,32 +0,0 @@ -// Implement a function repeatStr -const repeatStr = require("./repeat-str"); -// Given a target string `str` and a positive integer `count`, -// When the repeatStr function is called with these inputs, -// Then it should: - -// Case: handle multiple repetitions: -// Given a target string `str` and a positive integer `count` greater than 1, -// When the repeatStr function is called with these inputs, -// Then it should return a string that contains the original `str` repeated `count` times. - -test("should repeat the string count times", () => { - const str = "hello"; - const count = 3; - const repeatedStr = repeatStr(str, count); - expect(repeatedStr).toEqual("hellohellohello"); -}); - -// Case: handle count of 1: -// Given a target string `str` and a `count` equal to 1, -// When the repeatStr function is called with these inputs, -// Then it should return the original `str` without repetition. - -// Case: Handle count of 0: -// Given a target string `str` and a `count` equal to 0, -// When the repeatStr function is called with these inputs, -// Then it should return an empty string. - -// Case: Handle negative count: -// Given a target string `str` and a negative integer `count`, -// When the repeatStr function is called with these inputs, -// Then it should throw an error, as negative counts are not valid. diff --git a/Sprint-3/3-dead-code/README.md b/Sprint-3/3-dead-code/README.md deleted file mode 100644 index 2bfbfff81..000000000 --- a/Sprint-3/3-dead-code/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Refactoring Dead Code - -Here are two example of code that has not been built efficiently. Both files have dead code in them. It's your job to go back through this existing code, identify the dead code, and remove it so the code is ready for production. - -## Instructions - -1. Work through each `exercise` file inside this directory. -2. Delete the dead code. -3. Commit your changes and make a PR when done. diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js deleted file mode 100644 index 4d09f15fa..000000000 --- a/Sprint-3/3-dead-code/exercise-1.js +++ /dev/null @@ -1,17 +0,0 @@ -// 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"; - -function sayHello(greeting, name) { - const greetingStr = greeting + ", " + name + "!"; - return `${greeting}, ${name}!`; - console.log(greetingStr); -} - -testName = "Aman"; - -const greetingMessage = sayHello(greeting, testName); - -console.log(greetingMessage); // 'hello, Aman!' diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js deleted file mode 100644 index 56d7887c4..000000000 --- a/Sprint-3/3-dead-code/exercise-2.js +++ /dev/null @@ -1,28 +0,0 @@ -// Remove the unused code that does not contribute to the final console log -// 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 = {}; - - 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 diff --git a/Sprint-3/4-stretch/README.md b/Sprint-3/4-stretch/README.md deleted file mode 100644 index 8f01227bf..000000000 --- a/Sprint-3/4-stretch/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# 🔍 Stretch - -These stretch activities are not mandatory, but we hope you will explore them after you have completed the mandatory work. - -In this exercise, you'll need to **play computer** with the function `find`. This function makes use of while loop statement. Your task will be to step through the code to figure out what is happening when the computer executes the code. - -Next, try implementing the functions specified in `password-validator.js`. - -Finally, set up your own script and test files for `card-validator.md` diff --git a/Sprint-3/4-stretch/card-validator.md b/Sprint-3/4-stretch/card-validator.md deleted file mode 100644 index e39c6ace6..000000000 --- a/Sprint-3/4-stretch/card-validator.md +++ /dev/null @@ -1,35 +0,0 @@ -## **PROJECT: Credit Card Validator** - -In this project you'll write a script that validates whether or not a credit card number is valid. - -Here are the rules for a valid number: - -- Number must be 16 digits, all of them must be numbers. -- You must have at least two different digits represented (all of the digits cannot be the same). -- The final digit must be even. -- The sum of all the digits must be greater than 16. - -For example, the following credit card numbers are valid: - -```markdown -9999777788880000 -6666666666661666 -``` - -And the following credit card numbers are invalid: - -```markdown -a92332119c011112 (invalid characters) -4444444444444444 (only one type of number) -1111111111111110 (sum less than 16) -6666666666666661 (odd final number) -``` - -These are the requirements your project needs to fulfill: - -- Make a JavaScript file with a name that describes its contents. -- Create a function with a descriptive name which makes it clear what the function does. The function should take one argument, the credit card number to validate. -- Write at least 2 comments that explain to others what a line of code is meant to do. -- Return a boolean from the function to indicate whether the credit card number is valid. - -Good luck! diff --git a/Sprint-3/4-stretch/find.js b/Sprint-3/4-stretch/find.js deleted file mode 100644 index c7e79a2f2..000000000 --- a/Sprint-3/4-stretch/find.js +++ /dev/null @@ -1,25 +0,0 @@ -function find(str, char) { - let index = 0; - - while (index < str.length) { - if (str[index] === char) { - return index; - } - index++; - } - return -1; -} - -console.log(find("code your future", "u")); -console.log(find("code your future", "z")); - -// The while loop statement allows us to do iteration - the repetition of a certain number of tasks according to some condition -// See the docs https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while - -// Use the Python Visualiser to help you play computer with this example and observe how this code is executed -// Pay particular attention to the following: - -// a) How the index variable updates during the call to find -// b) What is the if statement used to check -// c) Why is index++ being used? -// d) What is the condition index < str.length used for? diff --git a/Sprint-3/4-stretch/password-validator.js b/Sprint-3/4-stretch/password-validator.js deleted file mode 100644 index b55d527db..000000000 --- a/Sprint-3/4-stretch/password-validator.js +++ /dev/null @@ -1,6 +0,0 @@ -function passwordValidator(password) { - return password.length < 5 ? false : 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 deleted file mode 100644 index 8fa3089d6..000000000 --- a/Sprint-3/4-stretch/password-validator.test.js +++ /dev/null @@ -1,26 +0,0 @@ -/* -Password Validation - -Write a program that should check if a password is valid -and returns a boolean - -To be valid, a password must: -- Have at least 5 characters. -- Have at least one English uppercase letter (A-Z) -- Have at least one English lowercase letter (a-z) -- Have at least one number (0-9) -- Have at least one of the following non-alphanumeric symbols: ("!", "#", "$", "%", ".", "*", "&") -- Must not be any previous password in the passwords array. - -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 diff --git a/Sprint-3/readme.md b/Sprint-3/readme.md deleted file mode 100644 index 028950b92..000000000 --- a/Sprint-3/readme.md +++ /dev/null @@ -1,18 +0,0 @@ -# 🧭 Guide to week 3 exercises - -> https://programming.codeyourfuture.io/structuring-data/sprints/3/prep/ - -> [!TIP] -> You should always do the prep work _before_ attempting the coursework. -> The prep shows you how to do the coursework. -> There is often a step by step video you can code along with too. -> Do the prep. - -This sprint you are expected to produce multiple different pull requests: - -1. One pull request for the `1-implement-and-rewrite-tests` directory. -2. One pull request for the `2-practice-tdd` directory. -3. One pull request for the `3-dead-code` directory. -4. Optionally, one pull request for the `4-stretch` directory. - -Each directory contains a README.md file with instructions for that directory.