From ca7fa61638e4622b192101b5ce9056eba6e75faa Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Mon, 2 Mar 2026 11:14:50 +0000 Subject: [PATCH 01/19] removed let from the code --- Sprint-2/1-key-errors/0.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..730d5b973c 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,21 @@ // Predict and explain first... -// =============> write your prediction here +// I think this function is meant to make the first letter of a string into uppercase then return the string // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring +//function capitalise(str) { + // let str = `${str[0].toUpperCase()}${str.slice(1)}`; + // return str; +//} + +// I got the error "SyntaxError: Identifier 'str' has already been declared" +// This is because str had been declared in line 7 and let str in line 8 is also trying to declare str + +// to fix this, I just removed the word let in line 8. This gave a value to str without trying to declare it again +// I ran the new code and there were no errors + function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; + str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; -} - -// =============> write your explanation here -// =============> write your new code here +} \ No newline at end of file From 11b3da18556cdd71750714688dc87b5f26776a71 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Mon, 2 Mar 2026 13:32:48 +0000 Subject: [PATCH 02/19] moved const outside the function --- Sprint-2/1-key-errors/1.js | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..5c4076935d 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,20 +1,43 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> write your prediction here +// decimalNumber is defined within the function so it will not be recognised in console.log(decimalNumber); // Try playing computer with the example to work out what is going on + + + function convertToPercentage(decimalNumber) { const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; return percentage; -} +``} console.log(decimalNumber); -// =============> write your explanation here + +// this is a function to convert a decimal number to a percentage - function declared +// the decimal number is declared as 0.5 +// percentage is calculated by multiplying the decimal number by 100 and then adding the % symbol +// the answer returned is named percentage and gives a number followed by % +// the answer will be printed in console // Finally, correct the code to fix the problem -// =============> write your new code here +// the error was actually 'decimalNumber' has already been declared +// this was because decimalNumber was declared inside the function convertToPercentage(decimalNumber) and +// declared again within the function with the const statement +// once const decimalNumber = 0.5; was moved outside the function this error was resolved +// that way the global decimalNumber exists and the function can still accept it as an argument + + +// const decimalNumber = 0.5; +// function convertToPercentage(decimalNumber) { +// const percentage = `${decimalNumber * 100}%`; + +// return percentage; +} + +// console.log(decimalNumber); + From b50bc9a87d77a69b7f29d3013cdebdb1351e07e7 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Mon, 2 Mar 2026 13:50:32 +0000 Subject: [PATCH 03/19] changed function --- Sprint-2/1-key-errors/2.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..f5c0a4f64b 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -3,18 +3,23 @@ // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here +// =============> I think that return can only return a value not do a calculation +// so this will return an error because it is trying to do a calculation instead of returning a value function square(3) { return num * num; } -// =============> write the error message here +// =============> SyntaxError: Unexpected number -// =============> explain this error message here +// =============> this is because variables and parameters in functions cannot start with a number or be a number +// however, return can be used for calculations so my prediction was wrong // Finally, correct the code to fix the problem -// =============> write your new code here - +// function square (num) { +// return num * num; +// } +// console.log(square(5)); +// ran console.log to ensure it works From b799ad0660d3e87fdd100c3181b15f1ef6e6dc57 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Mon, 2 Mar 2026 15:41:32 +0000 Subject: [PATCH 04/19] added return --- Sprint-2/2-mandatory-debug/0.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..78dec50fed 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,14 +1,29 @@ // Predict and explain first... -// =============> write your prediction here +// =============> when the console.log outside the function is performed $(multiply(10, 32)) +// it will print the text The result of multiplying by 10 and 32 is +// but then will state undefined for the value -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 +// =============> there is no return +// console.log(a*B) printed the result of multiplying a and b but because there is no return +// the answer was not returned to the function so the console.log outside the function did not +// receive the value and printed undefined instead // Finally, correct the code to fix the problem -// =============> write your new code here +// =============> + function multiply(a, b) { + return a * b; + } + + console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); + +// I removed the first console.log because it didn't seem necessary to print out 320 but +// if you need to print 320 as well as the final console-log statement then console.log(a * b) +// can be added back in but it would need to be before the return statement because if it is +// after the return statement it will never be reached and the value will not be printed out \ No newline at end of file From 7e54a8eaf1bbc21dcefd3af574f0ccccab31e29b Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Mon, 2 Mar 2026 15:48:24 +0000 Subject: [PATCH 05/19] added return and removed first console.log --- Sprint-2/2-mandatory-debug/0.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index 78dec50fed..8820c739c1 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -20,7 +20,6 @@ function multiply(a, b) { return a * b; } - console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // I removed the first console.log because it didn't seem necessary to print out 320 but From 5658f41d4fa9c437da2d57c76d3f70fd99977cd4 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Mon, 2 Mar 2026 15:56:05 +0000 Subject: [PATCH 06/19] removed semi-colon --- Sprint-2/2-mandatory-debug/1.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcfd..3770db7e9c 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,6 @@ // Predict and explain first... -// =============> write your prediction here +// =============> the function so will not perform a + b and will return undefined in the + console.log function function sum(a, b) { return; @@ -8,6 +9,14 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); -// =============> write your explanation here +// =============> there shouldn't be a semi-colon after return +// this will signify the end of function so a + b will not be performed +// therefore there is no answer to return to print in the console.log function + // 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 80c54914981643707225373848dbd5e36d898c23 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Mon, 2 Mar 2026 16:44:45 +0000 Subject: [PATCH 07/19] removed const and added parameter to function --- Sprint-2/2-mandatory-debug/2.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..9b9db21efd 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,7 +1,9 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// =============> the function has no parameter so will use the +// global value of num for num.toString which means it will always +// return 3 which is the last digit of 103 const num = 103; @@ -14,11 +16,28 @@ 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 last digit of 42 is 3 +//The last digit of 105 is 3 +//The last digit of 806 is 3 + // Explain why the output is the way it is -// =============> write your explanation here +// =============> the function has no parameter so will use the +// global value of num for num.toString + // Finally, correct the code to fix the problem -// =============> write your new code here +// =============> +// function getLastDigit(num) { +// 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)}`); + +// removed const num = 103; and added num as a parameter to the function +// getLastDigit so that it can take in the value of num when the function is +// called and return the last digit of that number instead of always using +// the global value of num which was 103. // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem From 6ea4caee63fc380df20b40beac4417d513a44573 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Mon, 2 Mar 2026 16:56:36 +0000 Subject: [PATCH 08/19] function to calculate bmi --- Sprint-2/3-mandatory-implement/1-bmi.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1b..f1b64430d4 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,7 @@ // 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 -} \ No newline at end of file + const bmi = weight / (height * height); + return bmi.toFixed(1); +} +console.log(calculateBMI(70, 1.73)); \ No newline at end of file From b3c99f8a329e63bc696ec62ba243151808fc8c90 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Mon, 2 Mar 2026 18:11:11 +0000 Subject: [PATCH 09/19] function to make a string into upper Snake Case --- Sprint-2/3-mandatory-implement/2-cases.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad9..76acac2945 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,18 @@ // You will need to come up with an appropriate name for the function // Use the MDN string documentation to help you find a solution // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase + +function toUpperSnakeCase(str) { + + return str.toUpperCase().split('').map(function(c) { + // splits string into individual characters and maps each character to a new value + + return /[A-Z0-9]/.test(c) ? c : '_'; + // checks if the character is an uppercase letter or a digit + + }).join(''); + // joins the array of characters back into a single string with underscores instead of spaces +} + +console.log(toUpperSnakeCase("there-once was/a young lady from+London")); +console.log(toUpperSnakeCase("hello.world! test+123")); From 8878027f621113c49f7f5b80b58ae7043a7ad9b8 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Mon, 2 Mar 2026 18:29:35 +0000 Subject: [PATCH 10/19] updated --- Sprint-2/1-key-errors/0.js | 2 +- Sprint-2/3-mandatory-implement/3-to-pounds.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 730d5b973c..2c67cc5ab2 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,5 +1,5 @@ // Predict and explain first... -// I think this function is meant to make the first letter of a string into uppercase then return the string +// I think this function capitalise is meant to make the first letter of a string into uppercase then return the string // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a703..7226b5002e 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,21 @@ // 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 +//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}`); \ No newline at end of file From 803168d141256ee6c22ea39eca85b755983a134e Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Mon, 2 Mar 2026 20:01:42 +0000 Subject: [PATCH 11/19] function to convert pence to pounds and pence --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 35 ++++++++----------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 7226b5002e..26d0084170 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -1,24 +1,17 @@ -// In Sprint-1, there is a program written in interpret/to-pounds.js - -// 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 -//const penceString = "399p"; - -const penceStringWithoutTrailingP = penceString.substring( - 0, - penceString.length - 1 -); +function getPenceString(penceString){ +const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1); + //removes p const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); -const pounds = paddedPenceNumberString.substring( - 0, - paddedPenceNumberString.length - 2 -); - -const pence = paddedPenceNumberString - .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); + //puts zeros in front of number if less than 3 digits +const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2); + //removes last 2 digits to get pounds +const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); + //gets last 2 digits to get pence, if less than 2 digits adds zeros to end of string but shouldnt be less than 3 + //due to padStart above +return `£${pounds}.${pence}`; + // returns string with pounds and pence in correct format +} -console.log(`£${pounds}.${pence}`); \ No newline at end of file +console.log(getPenceString("399p")); + // tested with 123p 1200p 24589p 89p 9p 0p \ No newline at end of file From be895638d8ee781c68f824d8717f3a04b433617c Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Mon, 2 Mar 2026 20:27:20 +0000 Subject: [PATCH 12/19] answered questions --- Sprint-2/4-mandatory-interpret/time-format.js | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8c..86e63805d3 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -11,24 +11,38 @@ function formatTimeDisplay(seconds) { return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } +console.log(formatTimeDisplay(61)); // 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 // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> pad will be called 3 times, once for pad(totalHours, +// once for (pad)remainingMinutes and once for (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 +// =============> The first call to pad is pad(totalHours). +totalHours is calculated as totalMinutes // 60. +For the input 61, seconds is 61, remainingSeconds is 1, and totalMinutes is 1. +So, totalHours is 1 // 60 = 0. +Therefore, num is assigned the value 0 when pad is called for the first time. + // c) What is the return value of pad is called for the first time? -// =============> write your answer here +// =============> The first call to pad is pad(totalHours). +totalHours is calculated as totalMinutes // 60. +For the input 61, totalMinutes is (61 - 1) // 60 = 1. +So, totalHours is 1 // 60 = 0. +pad(0) returns the string representation of 0, padded with zeros to a minimum length of 2, which is "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 +// =============> We look at the last call to pad, which is pad(remaining_seconds). +remaining_seconds is calculated as seconds % 60. +For the input 61, seconds % 60 equals 1. +So, pad(remaining_seconds) is equivalent to pad(1). Therefore, the value assigned to num in the last call to pad is 1. // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> write your answer here +// =============> For the input 61, remaining_seconds will be 1. So, pad(1) will return "01". Therefore, the value assigned to num is 1. \ No newline at end of file From 244451e8f4cb289935cffa35eac47746c78a1ad3 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Tue, 3 Mar 2026 09:10:09 +0000 Subject: [PATCH 13/19] completed exercises --- Sprint-2/5-stretch-extend/format-time.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b8..d3a5eb0555 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -1,6 +1,7 @@ // 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. +// 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)); @@ -23,3 +24,5 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +console.log formatAs12HourClock("14:00"); // 2pm \ No newline at end of file From 3f9f36220be944190768ba48436b0570ea353310 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Tue, 3 Mar 2026 09:10:42 +0000 Subject: [PATCH 14/19] exercises --- Sprint-1/2-mandatory-errors/4.js | 2 +- Sprint-2/5-stretch-extend/format-time.js | 2 +- .../implement/1-get-angle-type.js | 10 +++++++++- .../implement/2-is-proper-fraction.js | 7 ++++++- .../implement/3-get-card-value.js | 9 ++++++++- Sprint-3/2-practice-tdd/get-ordinal-number.js | 13 +++++++++++-- 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d1..25ef4179b5 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,2 @@ const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const 24hourClockTime = "08:53"; diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index d3a5eb0555..2d8120da51 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -25,4 +25,4 @@ console.assert( `current output: ${currentOutput2}, target output: ${targetOutput2}` ); -console.log formatAs12HourClock("14:00"); // 2pm \ No newline at end of file +console.log formatAs12HourClock("14:00"); // should return "2:00 pm" diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index 9e05a871e2..e041fa6f27 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,18 @@ // 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) { +//function getAngleType(angle) { // TODO: Implement this function +//} + +function getAngleType(angle) { + if (angle > 0 && angle < 90) return 'Acute angle'; // Angles between 0 and 90 + if (angle === 90) return 'Right angle'; // Exactly 90 degrees + if (angle > 90 && angle < 180) return 'Obtuse angle'; // Angles between 90 and 180 + return 'Invalid angle'; // For angles that don't fit any type } + // 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; diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index 970cb9b641..914f3a2d33 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 @@ -10,10 +10,15 @@ // 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) { +//function isProperFraction(numerator, denominator) { // TODO: Implement this function +//} +function isProperFraction(numerator, denominator) { + if (denominator === 0) return false; // Handle zero denominator case + return numerator < denominator; // Normal fraction check } + // 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; 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 c7559e787e..e8bda962c7 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,10 +21,17 @@ // After you have implemented the function, write tests to cover all the cases, and // execute the code to ensure all tests pass. -function getCardValue(card) { +//function getCardValue(card) { // TODO: Implement this function +//} + +function getCardValue(card) { + if (card === 'A♠' || card === 'A♥' || card === 'A♦' || card === 'A♣') return 11; // Ace value + // handle other card values... + return undefined; // Handle invalid cards } + // 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; diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db13..0bc1ef2548 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,14 @@ -function getOrdinalNumber(num) { - return "1st"; +//function getOrdinalNumber(num) { +// return "1st"; +//} + +//module.exports = getOrdinalNumber; + +function getOrdinalNumber(n) { + const suffix = (n % 10 === 1 && n % 100 !== 11) ? 'st' : + (n % 10 === 2 && n % 100 !== 12) ? 'nd' : + (n % 10 === 3 && n % 100 !== 13) ? 'rd' : 'th'; + return `${n}${suffix}`; } module.exports = getOrdinalNumber; From be57b2d24ca8ff3e79c4b27c48986d4963338ed2 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Wed, 4 Mar 2026 08:52:58 +0000 Subject: [PATCH 15/19] updating changes --- Sprint-2/2-mandatory-debug/0.js | 2 +- Sprint-2/2-mandatory-debug/1.js | 2 +- Sprint-2/2-mandatory-debug/2.js | 2 +- Sprint-2/3-mandatory-implement/1-bmi.js | 2 +- Sprint-2/3-mandatory-implement/2-cases.js | 2 +- Sprint-2/3-mandatory-implement/3-to-pounds.js | 2 +- Sprint-2/4-mandatory-interpret/time-format.js | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index 8820c739c1..22a35c5d36 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -22,7 +22,7 @@ } console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// I removed the first console.log because it didn't seem necessary to print out 320 but +// I removed the first console.log because it didn't seem necessary to print out 320 // if you need to print 320 as well as the final console-log statement then console.log(a * b) // can be added back in but it would need to be before the return statement because if it is // after the return statement it will never be reached and the value will not be printed out \ No newline at end of file diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 3770db7e9c..674a1ddc8f 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -9,7 +9,7 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); -// =============> there shouldn't be a semi-colon after return +// =============> I think there shouldn't be a semi-colon after return // this will signify the end of function so a + b will not be performed // therefore there is no answer to return to print in the console.log function diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 9b9db21efd..77f57cd950 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -34,7 +34,7 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`); // console.log(`The last digit of 105 is ${getLastDigit(105)}`); // console.log(`The last digit of 806 is ${getLastDigit(806)}`); -// removed const num = 103; and added num as a parameter to the function +// removed const num = 103; and then added num as a parameter to the function // getLastDigit so that it can take in the value of num when the function is // called and return the last digit of that number instead of always using // the global value of num which was 103. diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index f1b64430d4..c5dffcf6c3 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,7 +15,7 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - const bmi = weight / (height * height); + const bmi = weight / (height * height); //calculation to calculate BMI return bmi.toFixed(1); } console.log(calculateBMI(70, 1.73)); \ 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 index 76acac2945..b21bb6523c 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -24,7 +24,7 @@ function toUpperSnakeCase(str) { // checks if the character is an uppercase letter or a digit }).join(''); - // joins the array of characters back into a single string with underscores instead of spaces + // joins the array of characters back into a single string and replaces spaces with underscores } console.log(toUpperSnakeCase("there-once was/a young lady from+London")); diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 26d0084170..4041941244 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -14,4 +14,4 @@ return `£${pounds}.${pence}`; } console.log(getPenceString("399p")); - // tested with 123p 1200p 24589p 89p 9p 0p \ No newline at end of file + // tested with 123p 1200p 24589p 89p 9p and 0p \ No newline at end of file diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 86e63805d3..fdc30cdb25 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -42,7 +42,7 @@ pad(0) returns the string representation of 0, padded with zeros to a minimum le // =============> We look at the last call to pad, which is pad(remaining_seconds). remaining_seconds is calculated as seconds % 60. For the input 61, seconds % 60 equals 1. -So, pad(remaining_seconds) is equivalent to pad(1). Therefore, the value assigned to num in the last call to pad is 1. +So, pad(remaining_seconds) is equivalent to pad(1). The value assigned to num in the last call to pad is 1. // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer // =============> For the input 61, remaining_seconds will be 1. So, pad(1) will return "01". Therefore, the value assigned to num is 1. \ No newline at end of file From ea0f877bf1071b7fcc534837f5edfe38d0acf282 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Thu, 5 Mar 2026 18:05:20 +0000 Subject: [PATCH 16/19] put in missing comments slashes --- Sprint-2/4-mandatory-interpret/time-format.js | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index fdc30cdb25..4ff271b6e7 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -25,24 +25,24 @@ console.log(formatTimeDisplay(61)); // b) What is the value assigned to num when pad is called for the first time? // =============> The first call to pad is pad(totalHours). -totalHours is calculated as totalMinutes // 60. -For the input 61, seconds is 61, remainingSeconds is 1, and totalMinutes is 1. -So, totalHours is 1 // 60 = 0. -Therefore, num is assigned the value 0 when pad is called for the first time. +//totalHours is calculated as totalMinutes // 60. +//For the input 61, seconds is 61, remainingSeconds is 1, and totalMinutes is 1. +//So, totalHours is 1 // 60 = 0. +//Therefore, num is assigned the value 0 when pad is called for the first time. // c) What is the return value of pad is called for the first time? // =============> The first call to pad is pad(totalHours). -totalHours is calculated as totalMinutes // 60. -For the input 61, totalMinutes is (61 - 1) // 60 = 1. -So, totalHours is 1 // 60 = 0. -pad(0) returns the string representation of 0, padded with zeros to a minimum length of 2, which is "00". +//totalHours is calculated as totalMinutes // 60. +//For the input 61, totalMinutes is (61 - 1) // 60 = 1. +//So, totalHours is 1 // 60 = 0. +//pad(0) returns the string representation of 0, padded with zeros to a minimum length of 2, which is "00". // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer // =============> We look at the last call to pad, which is pad(remaining_seconds). -remaining_seconds is calculated as seconds % 60. -For the input 61, seconds % 60 equals 1. -So, pad(remaining_seconds) is equivalent to pad(1). The value assigned to num in the last call to pad is 1. +//remaining_seconds is calculated as seconds % 60. +//For the input 61, seconds % 60 equals 1. +//So, pad(remaining_seconds) is equivalent to pad(1). The value assigned to num in the last call to pad is 1. // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> For the input 61, remaining_seconds will be 1. So, pad(1) will return "01". Therefore, the value assigned to num is 1. \ No newline at end of file +// For the input 61, remaining_seconds will be 1. So, pad(1) will return "01". Therefore, the value assigned to num is 1. \ No newline at end of file From e8c8bb8c7160502a71e8dda88a123580d293ee2c Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Thu, 5 Mar 2026 18:24:43 +0000 Subject: [PATCH 17/19] Delete Sprint-1/2-mandatory-errors/4.js --- Sprint-1/2-mandatory-errors/4.js | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 Sprint-1/2-mandatory-errors/4.js diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js deleted file mode 100644 index 25ef4179b5..0000000000 --- a/Sprint-1/2-mandatory-errors/4.js +++ /dev/null @@ -1,2 +0,0 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; From 17f37321b52154f01fc542bfdd12512e5d8aa13e Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Thu, 5 Mar 2026 18:25:20 +0000 Subject: [PATCH 18/19] Delete Sprint-1/1-key-exercises directory --- Sprint-1/1-key-exercises/1-count.js | 6 ------ Sprint-1/1-key-exercises/2-initials.js | 11 ----------- Sprint-1/1-key-exercises/3-paths.js | 23 ----------------------- Sprint-1/1-key-exercises/4-random.js | 9 --------- 4 files changed, 49 deletions(-) delete mode 100644 Sprint-1/1-key-exercises/1-count.js delete mode 100644 Sprint-1/1-key-exercises/2-initials.js delete mode 100644 Sprint-1/1-key-exercises/3-paths.js delete mode 100644 Sprint-1/1-key-exercises/4-random.js diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js deleted file mode 100644 index 117bcb2b6e..0000000000 --- a/Sprint-1/1-key-exercises/1-count.js +++ /dev/null @@ -1,6 +0,0 @@ -let count = 0; - -count = count + 1; - -// Line 1 is a variable declaration, creating the count variable with an initial value of 0 -// Describe what line 3 is doing, in particular focus on what = is doing diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js deleted file mode 100644 index 47561f6175..0000000000 --- a/Sprint-1/1-key-exercises/2-initials.js +++ /dev/null @@ -1,11 +0,0 @@ -let firstName = "Creola"; -let middleName = "Katherine"; -let lastName = "Johnson"; - -// Declare a variable called initials that stores the first character of each string. -// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. - -let initials = ``; - -// https://www.google.com/search?q=get+first+character+of+string+mdn - diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js deleted file mode 100644 index ab90ebb28e..0000000000 --- a/Sprint-1/1-key-exercises/3-paths.js +++ /dev/null @@ -1,23 +0,0 @@ -// The diagram below shows the different names for parts of a file path on a Unix operating system - -// ┌─────────────────────┬────────────┐ -// │ dir │ base │ -// ├──────┬ ├──────┬─────┤ -// │ root │ │ name │ ext │ -// " / home/user/dir / file .txt " -// └──────┴──────────────┴──────┴─────┘ - -// (All spaces in the "" line should be ignored. They are purely for formatting.) - -const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; -const lastSlashIndex = filePath.lastIndexOf("/"); -const base = filePath.slice(lastSlashIndex + 1); -console.log(`The base part of ${filePath} is ${base}`); - -// Create a variable to store the dir part of the filePath variable -// Create a variable to store the ext part of the variable - -const dir = ; -const ext = ; - -// https://www.google.com/search?q=slice+mdn \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js deleted file mode 100644 index 292f83aabb..0000000000 --- a/Sprint-1/1-key-exercises/4-random.js +++ /dev/null @@ -1,9 +0,0 @@ -const minimum = 1; -const maximum = 100; - -const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; - -// In this exercise, you will need to work out what num represents? -// Try breaking down the expression and using documentation to explain what it means -// It will help to think about the order in which expressions are evaluated -// Try logging the value of num and running the program several times to build an idea of what the program is doing From b771cf41f7d3f338225b78e4eaf2f57d1922aeac Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Thu, 5 Mar 2026 18:25:38 +0000 Subject: [PATCH 19/19] Delete Sprint-3 directory --- .../1-implement-and-rewrite-tests/README.md | 47 ---------- .../implement/1-get-angle-type.js | 45 --------- .../implement/2-is-proper-fraction.js | 38 -------- .../implement/3-get-card-value.js | 59 ------------ .../1-get-angle-type.test.js | 20 ---- .../2-is-proper-fraction.test.js | 10 -- .../3-get-card-value.test.js | 20 ---- .../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 | 14 --- .../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 ---- 24 files changed, 617 deletions(-) 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-3/1-implement-and-rewrite-tests/README.md b/Sprint-3/1-implement-and-rewrite-tests/README.md deleted file mode 100644 index a65bd2077c..0000000000 --- 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 e041fa6f27..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ /dev/null @@ -1,45 +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. - -//function getAngleType(angle) { - // TODO: Implement this function -//} - -function getAngleType(angle) { - if (angle > 0 && angle < 90) return 'Acute angle'; // Angles between 0 and 90 - if (angle === 90) return 'Right angle'; // Exactly 90 degrees - if (angle > 90 && angle < 180) return 'Obtuse angle'; // Angles between 90 and 180 - return 'Invalid angle'; // For angles that don't fit any type -} - - -// The line below allows us to load the getAngleType function into tests in other files. -// This will be useful in the "rewrite tests with jest" step. -module.exports = getAngleType; - -// This helper function is written to make our assertions easier to read. -// If the actual output matches the target output, the test will pass -function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); -} - -// TODO: Write tests to cover all cases, including boundary and invalid cases. -// Example: Identify Right Angles -const right = getAngleType(90); -assertEquals(right, "Right angle"); diff --git a/Sprint-3/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 914f3a2d33..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ /dev/null @@ -1,38 +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. - -// 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) { - if (denominator === 0) return false; // Handle zero denominator case - return numerator < denominator; // Normal fraction check -} - - -// 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? - -// Example: 1/2 is a proper fraction -assertEquals(isProperFraction(1, 2), true); diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js deleted file mode 100644 index e8bda962c7..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ /dev/null @@ -1,59 +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. - -//function getCardValue(card) { - // TODO: Implement this function -//} - -function getCardValue(card) { - if (card === 'A♠' || card === 'A♥' || card === 'A♦' || card === 'A♣') return 11; // Ace value - // handle other card values... - return undefined; // Handle invalid cards -} - - -// 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. -// Examples: -assertEquals(getCardValue("9♠"), 9); - -// Handling invalid cards -try { - getCardValue("invalid"); - - // This line will not be reached if an error is thrown as expected - console.error("Error was not thrown for invalid card"); -} catch (e) {} - -// What other invalid card cases can you think of? 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 d777f348d3..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js +++ /dev/null @@ -1,20 +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 -// Case 3: Obtuse angles -// Case 4: Straight angle -// Case 5: Reflex angles -// Case 6: Invalid angles 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 7f087b2ba1..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ /dev/null @@ -1,10 +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 zero`, () => { - expect(isProperFraction(1, 0)).toEqual(false); -}); 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 cf7f9dae2e..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ /dev/null @@ -1,20 +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); -}); - -// 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 917194e7a9..0000000000 --- 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 f7d82fe43d..0000000000 --- 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 95b6ebb7d4..0000000000 --- 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 179ea0ddf7..0000000000 --- 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 0bc1ef2548..0000000000 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ /dev/null @@ -1,14 +0,0 @@ -//function getOrdinalNumber(num) { -// return "1st"; -//} - -//module.exports = getOrdinalNumber; - -function getOrdinalNumber(n) { - const suffix = (n % 10 === 1 && n % 100 !== 11) ? 'st' : - (n % 10 === 2 && n % 100 !== 12) ? 'nd' : - (n % 10 === 3 && n % 100 !== 13) ? 'rd' : 'th'; - return `${n}${suffix}`; -} - -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 adfa58560f..0000000000 --- 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 3838c7b003..0000000000 --- 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 a3fc1196c4..0000000000 --- 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 2bfbfff819..0000000000 --- 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 4d09f15fa9..0000000000 --- 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 56d7887c4c..0000000000 --- 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 8f01227bf9..0000000000 --- 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 e39c6ace6e..0000000000 --- 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 c7e79a2f21..0000000000 --- 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 b55d527dba..0000000000 --- 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 8fa3089d6b..0000000000 --- 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 028950b927..0000000000 --- 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.