From 9fe8e3b8cbb90bbcfa01edf34ae1e60e40296521 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Mon, 11 May 2026 13:43:12 +0100 Subject: [PATCH 01/45] Explain "count = count + 1" Explain "count = count + 1" --- Sprint-1/1-key-exercises/1-count.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6e..34556e9591 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -2,5 +2,9 @@ let count = 0; count = count + 1; +// The single equals means assignment. +// It is saying the value of count is now the previous value of count plus one. +//If it was == or ===, it would be testing equality and asking if count (0) is equal to 0+1 which would give false. + // 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 From 2c99f4a0453a6306ee83cec214de5e76820239a2 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Mon, 11 May 2026 13:52:13 +0100 Subject: [PATCH 02/45] Get first initials and concatenate them Get first initials and concatenate them --- Sprint-1/1-key-exercises/2-initials.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f6175..ee0cfe2b94 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,9 @@ 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 = ``; +let initials = firstName[0] + middleName[0] + lastName[0]; + +console.log(initials) // https://www.google.com/search?q=get+first+character+of+string+mdn From c811a4e4d99dcdd00dad959a3af20487e794ee5d Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Tue, 12 May 2026 15:25:10 +0100 Subject: [PATCH 03/45] Update 3-paths.js --- Sprint-1/1-key-exercises/3-paths.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28e..e167672346 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,10 @@ 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 = ; +const dir = filePath.slice(0,lastSlashIndex); +console.log(`The dir part of ${filePath} is ${dir}`); -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +const ext = base.split(".").slice(1) +console.log(`The ext part of ${filePath} is ${ext}`); + +// https://www.google.com/search?q=slice+mdn From b53d2f250a59b929a330c8cc8793f8a86d3f7632 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Tue, 12 May 2026 15:51:27 +0100 Subject: [PATCH 04/45] Update 4-random.js --- Sprint-1/1-key-exercises/4-random.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aabb..a359ad2e09 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,3 +7,10 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // 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 + +// get the maximum minus minimum +// add 1 to count the edges and avoid the fencepost error +// this generates the correct span +// add the minimum on so it starts at the right number +// multiply it by a random decimal between 0 and 1 +// round it down to the next whole number down From f3f64c3e1407115b2213d5da2811c1cc3831762c Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Wed, 13 May 2026 07:54:46 +0100 Subject: [PATCH 05/45] Update 0.js --- Sprint-1/2-mandatory-errors/0.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f7..044add7ac1 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,2 @@ -This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +// This is just an instruction for the first activity - but it is just for human consumption +// We don't want the computer to run these 2 lines - how can we solve this problem? From 6f33c1f51a1e0f725871d1d1994ed271dc0e483f Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Wed, 13 May 2026 07:56:02 +0100 Subject: [PATCH 06/45] Update 1.js --- Sprint-1/2-mandatory-errors/1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea76..031839b47d 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,4 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; From 442479d8841c7b7a6d0a10ea7d300e6a1758b726 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Wed, 13 May 2026 07:56:47 +0100 Subject: [PATCH 07/45] Update 2.js --- Sprint-1/2-mandatory-errors/2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831d..2865eb8a42 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,5 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? -console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); From df5bb9a74affa58f1328faaff6131f9c8a25740e Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Wed, 13 May 2026 08:16:58 +0100 Subject: [PATCH 08/45] Update 3.js --- Sprint-1/2-mandatory-errors/3.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884db..386e790d35 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,6 @@ -const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +const cardNumber = "4533787178994213"; +const last4Digits = cardNumber.slice(cardNumber.length-4,cardNumber.length); +console.log(last4Digits) // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working From 3e0991ee6f76c558fcb38843f0305e720994088d Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Wed, 13 May 2026 08:21:32 +0100 Subject: [PATCH 09/45] Change variable name to not start with a number Change variable name to not start with a number --- Sprint-1/2-mandatory-errors/4.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d1..b4f87d1d43 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 TwelveHourClockTime = "20:53"; +const TwentyFourHourClockTime = "08:53"; From 05646f88523dcd731e727fd6168a3aa38c9b281b Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Wed, 13 May 2026 08:47:02 +0100 Subject: [PATCH 10/45] answered questions answered questions --- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e18..fbc405ddcf 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -2,7 +2,7 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",","")); const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; @@ -12,11 +12,16 @@ console.log(`The percentage change is ${percentageChange}`); // Read the code and then answer the questions below // a) How many function calls are there in this file? Write down all the lines where a function call is made +// Five: two on line 4, two on line 5 and one on line 10. // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? +// Comma was missing on line 5. I've added it, the second comma here: .replaceAll(",","") // c) Identify all the lines that are variable reassignment statements +// lines 4 and 5 // d) Identify all the lines that are variable declarations +// lines 1, 2, 7 and 8 // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +// It takes the comma out of the numbers so it can be converted to a number one can do calculations with. The commas are just to make it more readable for humans. From 16f45c740a8d7df9840a2a729f180b9ea2e70bd9 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Wed, 13 May 2026 09:15:54 +0100 Subject: [PATCH 11/45] answer questions answer questions --- Sprint-1/3-mandatory-interpret/2-time-format.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d2395587..b54da76de5 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -12,14 +12,20 @@ console.log(result); // For the piece of code above, read the code and then answer the following questions // a) How many variable declarations are there in this program? +// 6 // b) How many function calls are there? +// 1 // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +// It's modulo. In this case, it gives the remainder of seconds after one gets the number of minutes by dividing by 60. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// It avoids using floor division, so it's more comprehensible to beginners, by subtracting the remaining seconds from the film length. The it divides by 60 to get hours. // e) What do you think the variable result represents? Can you think of a better name for this variable? +// It shows the time in hours, minutes and seconds. You could call it timeHoursMinsSecs // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// It wouldn't work well if the user typed the answer as a string. The input is unlikely to be negative or run over a day or have a user finnicky enough to state seconds with a decimal. It might look nicer if it was padded with zeros. From 1015d397ed1d151ebe3013045073e4842cd6e305 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Wed, 13 May 2026 10:19:20 +0100 Subject: [PATCH 12/45] answered the questions answered the questions as comments at the end --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69a..1d1d26edbf 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -1,16 +1,21 @@ const penceString = "399p"; +// remove last character const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1 ); +// pad to the length of three const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + +// remove the last two characters const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2 ); +// get last two characters and pad to two if needed const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0"); @@ -25,3 +30,9 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" + +// penceStringWithoutTrailingP: remove last character +// paddedPenceNumberString: pad to the length of three +// pounds: remove the last two characters of paddedPenceNumberString +// pence: get last two characters and pad to two if needed +// log to the console in the format £[pounds].[pence] From ecb2ea63aa15ab923a8d972e281362c5fda4914a Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Thu, 14 May 2026 13:42:08 +0100 Subject: [PATCH 13/45] fixed code and explained error fixed code and left comment explaining error --- Sprint-2/1-key-errors/0.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..f0eb49e34b 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -10,4 +10,14 @@ function capitalise(str) { } // =============> write your explanation here + +// Your need to delete "let ". That's just for making a new variables. You want assignment. + // =============> write your new code here + +function capitalise(str) { + str = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; +} + +console.log(capitalise("hello")); From 463b942c4bcaa0daa2bdeeeebda7b12618ed7113 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Thu, 14 May 2026 14:03:18 +0100 Subject: [PATCH 14/45] explained error and fixed code fixed code and explained error in comment --- Sprint-2/1-key-errors/1.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..db1f0c33f4 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -16,5 +16,14 @@ console.log(decimalNumber); // =============> write your explanation here +// You need to pass the value in, not declare it within the function. The syntax is wrong. + // 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)); From 115536307cc89e65339c2219928747fc882cbb1b Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Thu, 14 May 2026 15:33:26 +0100 Subject: [PATCH 15/45] corrected code and explained with comments corrected code and explained with comments --- Sprint-2/1-key-errors/2.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..5774cb268f 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -5,16 +5,28 @@ // =============> write your prediction of the error here +// num is not defined + function square(3) { return num * num; } // =============> write the error message here +// SyntaxError: Unexpected token (1:16) + // =============> explain this error message here +// You can't feed the value in there. You need to call it from outside the function. JS thinks it's a variable name which isn't allowed to start with a number. + // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} + +console.log(square(2)) + From 5f70bec7eef1ea6948b834126864de67e3aa4884 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Thu, 14 May 2026 15:42:20 +0100 Subject: [PATCH 16/45] fixed code and explained with comments fixed code and explained with comments --- Sprint-2/2-mandatory-debug/0.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..d0602130d6 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -2,6 +2,8 @@ // =============> write your prediction here +// The result of multiplying 10 and 32 is undefined + function multiply(a, b) { console.log(a * b); } @@ -10,5 +12,13 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +// Nothing is returned in the function but rather logged to the console + // 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)}`); From 2e416eff33f59f9c465523543f229e866777a121 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Fri, 15 May 2026 07:56:14 +0100 Subject: [PATCH 17/45] calculate BMI calculate BMI --- Sprint-2/3-mandatory-implement/1-bmi.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1b..1ade2f874d 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -16,4 +16,9 @@ function calculateBMI(weight, height) { // return the BMI of someone based off their weight and height -} \ No newline at end of file + function calculateBMI(weight, height) { + return (weight/(height**2)).toFixed(1) +} + +console.log (calculateBMI(70, 1.73)); +} From c3ecc0969aaad7d449b359a2b1ea762b4dce9aef Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Fri, 15 May 2026 08:59:11 +0100 Subject: [PATCH 18/45] Update 2-cases.js --- Sprint-2/3-mandatory-implement/2-cases.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad9..16eb4cea9d 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,9 @@ // 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 snakeCase(toConvert) { + return toConvert.replace(" ", "_").toUpperCase(); +} + +console.log(snakeCase("hello there")); From a70a9d8da5d60567b6b4366bc83c8b23cc30acc6 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Fri, 15 May 2026 13:26:06 +0100 Subject: [PATCH 19/45] fixed code and explained error in comments fixed code and explained error in comments --- Sprint-2/2-mandatory-debug/1.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcfd..1ee394f405 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,6 +1,8 @@ // Predict and explain first... // =============> write your prediction here +// It returns blank since it doesn't know what it's returning + function sum(a, b) { return; a + b; @@ -9,5 +11,14 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here + + return a + b is supposed to be on one line. "return;" just returns nothing + // 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 19bfed111ccc95447312546d61d2ac2535c215c9 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Fri, 15 May 2026 13:31:46 +0100 Subject: [PATCH 20/45] fixed code and wrote explanation in comments fixed code and wrote explanation in comments --- Sprint-2/2-mandatory-debug/2.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..eb585443ad 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -3,6 +3,8 @@ // Predict the output of the following code: // =============> Write your prediction here +// It's putting the answer to everything as 3, the last digit of the contant. + const num = 103; function getLastDigit() { @@ -15,10 +17,20 @@ 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 + +// My prediction was correct. + // Explain why the output is the way it is // =============> write your explanation here + +// function getLastDigit() should have "theNumber" or something in its brackets. It's getting the last digit of the constant as the answer to everything at the moment. + // Finally, correct the code to fix the problem // =============> write your new code here +function getLastDigit(num) { + return num.toString().slice(-1); +} + // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem From 6cb40ccfe8ad908140f88813622b7ca288ebd1d5 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Fri, 15 May 2026 13:41:23 +0100 Subject: [PATCH 21/45] put pounds program into a function put pounds program into a function --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a703..eea021b2d3 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,33 @@ // You will need to declare a function called toPounds with an appropriately named parameter. // You should call this function a number of times to check it works for different inputs + +function calculateBMI(penceString) { + + // remove last character + const penceStringWithoutTrailingP = penceString.substring( + 0, + penceString.length - 1 + ); + + // pad to the length of three + const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + + // remove the last two characters + const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 + ); + + // get last two characters and pad to two if needed + const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + + console.log(`£${pounds}.${pence}`); + +} + +console.log(calculateBMI("456p")) +console.log(calculateBMI("545747p")) +console.log(calculateBMI("1p")) From 3d272d67e54583ad7bf10138b22314182e6d71ad Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Fri, 15 May 2026 13:56:28 +0100 Subject: [PATCH 22/45] Update time-format.js --- Sprint-2/4-mandatory-interpret/time-format.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 17127bc01e..3cf66a1e98 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -21,18 +21,18 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> 3 // Call formatTimeDisplay with an input of 61, now answer the following: // b) What is the value assigned to num when pad is called for the first time? -// =============> write your answer here +// =============> 0 // c) What is the return value of pad is called for the first time? -// =============> write your answer here +// =============> "00" // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> write your answer here +// =============> 1 - Remaining seconds is calculated first with %60 and 1 is what's left over. // e) What is the return value of pad when it is called for the last time in this program? Explain your answer -// =============> write your answer here +// =============> "01" - now it's padded to 2 digits From f834c597ea98ee92b037275f1689bc0f3c93e9e8 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Tue, 19 May 2026 10:06:32 +0100 Subject: [PATCH 23/45] wrote tests --- .../1-get-angle-type.test.js | 36 +++++++++++++++++++ 1 file changed, 36 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 d777f348d3..985951882b 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,43 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle + +test(`should return "Right angle" when (angle === 90)`, () => { + // Test right angle + expect(getAngleType(90)).toEqual("Right angle"); +}); + // Case 3: Obtuse angles + +test(`should return "Obtuse angle" when (90 < angle < 180)`, () => { + // Test various obtuse angles, including boundary cases + expect(getAngleType(91)).toEqual("Obtuse angle"); + expect(getAngleType(145)).toEqual("Obtuse angle"); + expect(getAngleType(99)).toEqual("Obtuse angle"); +}); + // Case 4: Straight angle + +test(`should return "Straight angle" when (angle === 180)`, () => { + // Test straight angle + expect(getAngleType(180)).toEqual("Straight angle"); +}); + // Case 5: Reflex angles + +test(`should return "Reflex angle" when (180 < angle < 360)`, () => { + // Test various reflex angles, including boundary cases + expect(getAngleType(191)).toEqual("Reflex angle"); + expect(getAngleType(245)).toEqual("Reflex angle"); + expect(getAngleType(199)).toEqual("Reflex angle"); +}); + // Case 6: Invalid angles + +test(`should return "Invalid angle" when (angle < 0 || angle > 360)`, () => { + // Test various invalid angles, including boundary cases + expect(getAngleType(-1)).toEqual("Invalid angle"); + expect(getAngleType(395)).toEqual("Invalid angle"); + expect(getAngleType(389)).toEqual("Invalid angle"); +}); + From b50059ccb1fdafd3b7dd915e8016a3f5e0ce2f5e Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Fri, 29 May 2026 14:03:58 +0100 Subject: [PATCH 24/45] Update 3-get-card-value.test.js --- .../3-get-card-value.test.js | 50 +++++++++++++++++++ 1 file changed, 50 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 cf7f9dae2e..ce5b3770fc 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,56 @@ test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); +// Number cards +test("Should return 2 for 2♣", () => { + expect(getCardValue("2♣")).toEqual(2); +}); + +test("Should return 10 for 10♥", () => { + expect(getCardValue("10♥")).toEqual(10); +}); + +// Face cards +test("Should return 10 for J♦", () => { + expect(getCardValue("J♦")).toEqual(10); +}); + +test("Should return 10 for Q♠", () => { + expect(getCardValue("Q♠")).toEqual(10); +}); + +test("Should return 10 for K♣", () => { + expect(getCardValue("K♣")).toEqual(10); +}); + +// ========================================================= +// INVALID CARDS +// ========================================================= + +test("Should throw an error for 1♠", () => { + expect(() => getCardValue("1♠")).toThrowError(); +}); + +test("Should throw an error for A?", () => { + expect(() => getCardValue("A?")).toThrowError(); +}); + +test("Should throw an error for empty string", () => { + expect(() => getCardValue("")).toThrowError(); +}); + +test("Should throw an error for 11♣", () => { + expect(() => getCardValue("11♣")).toThrowError(); +}); + +test("Should throw an error for invalid rank", () => { + expect(() => getCardValue("Z♦")).toThrowError(); +}); + +test("Should throw an error for missing rank", () => { + expect(() => getCardValue("♠")).toThrowError(); +}); + // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) // Face Cards (J, Q, K) From 9c8066043203358c3fb6fc0d8dc1428fd4befe04 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Fri, 29 May 2026 14:04:43 +0100 Subject: [PATCH 25/45] Update 3-get-card-value.js --- .../implement/3-get-card-value.js | 25 ++++++++++++++++++- 1 file changed, 24 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 ff5c532e1d..a00afcc3c7 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 @@ -22,7 +22,30 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + if (card.length < 2 || card.length > 3) { + throw new Error("Invalid card"); + } + + const suit = card.slice(-1); + const rank = card.slice(0, -1); + + if (!"♥♦♣♠".includes(suit)) { + throw new Error("Invalid card"); + } + + if (/^[2-9]$/.test(rank) || rank === "10") { + return Number(rank); + } + + if (["J", "Q", "K"].includes(rank)) { + return 10; + } + + if (rank === "A") { + return 11; + } + + throw new Error("Invalid card"); } // The line below allows us to load the getCardValue function into tests in other files. From 07a945c2b601eed9f50aeedb8951bbebbfc54c10 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Sat, 30 May 2026 15:16:39 +0100 Subject: [PATCH 26/45] Update 1-get-angle-type.js --- .../implement/1-get-angle-type.js | 22 ++++++++++++++++++- 1 file changed, 21 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 9e05a871e2..8c14be696e 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -15,7 +15,27 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - // TODO: Implement this function + if (angle > 0 && angle < 90) { + return "Acute angle"; + } + + if (angle === 90) { + return "Right angle"; + } + + if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } + + if (angle === 180) { + return "Straight angle"; + } + + if (angle > 180 && angle < 360) { + return "Reflex angle"; + } + + return "Invalid angle"; } // The line below allows us to load the getAngleType function into tests in other files. From 152cad65d4f52800837d19df00e7bee71f4a77be Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Sat, 30 May 2026 15:22:49 +0100 Subject: [PATCH 27/45] Update 2-is-proper-fraction.js --- .../implement/2-is-proper-fraction.js | 3 ++- 1 file changed, 2 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 970cb9b641..07f6d0e10e 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 @@ -11,7 +11,8 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + if (denominator === 0) return false; + return Math.abs(numerator) < Math.abs(denominator); } // The line below allows us to load the isProperFraction function into tests in other files. From 2ed2285a9e7af02b7668239c28e8df9b5c9ca000 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Sat, 30 May 2026 15:51:30 +0100 Subject: [PATCH 28/45] Update 2-is-proper-fraction.test.js --- .../2-is-proper-fraction.test.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) 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 7f087b2ba1..7b0b9c26cd 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 @@ -8,3 +8,32 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); + +test("1/2 is proper", () => { + expect(isProperFraction(1, 2)).toBe(true); +}); + +test("3/2 is improper", () => { + expect(isProperFraction(3, 2)).toBe(false); +}); + +test("0/5 is proper", () => { + expect(isProperFraction(0, 5)).toBe(true); +}); + +test("denominator 0 is invalid", () => { + expect(isProperFraction(1, 0)).toBe(false); +}); + +test("-1/2 is proper", () => { + expect(isProperFraction(-1, 2)).toBe(true); +}); + +test("1/-2 is proper", () => { + expect(isProperFraction(1, -2)).toBe(true); +}); + +test("-3/2 is improper", () => { + expect(isProperFraction(-3, 2)).toBe(false); +}); + From 5893e7bdfe32890492d277ac5622d20ede7357e2 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Sat, 6 Jun 2026 15:47:48 +0100 Subject: [PATCH 29/45] Update count.js --- Sprint-3/2-practice-tdd/count.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..e5d67f4ba2 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,5 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + return text.split('').filter(x => x === char).length } module.exports = countChar; From b464d8f4363d86f4aa6d0ab93551023acf3d36d7 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Sat, 6 Jun 2026 15:55:30 +0100 Subject: [PATCH 30/45] Update count.test.js --- Sprint-3/2-practice-tdd/count.test.js | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf7..254b244d27 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -17,6 +17,46 @@ test("should count multiple occurrences of a character", () => { expect(count).toEqual(5); }); +// Scenario: No Occurrences +test("should return 0 when character is not present", () => { + const str = "hello"; + const char = "z"; + const count = countChar(str, char); + expect(count).toBe(0); +}); + +// Scenario: Single Occurrence +test("should count a single occurrence of a character", () => { + const str = "hello"; + const char = "h"; + const count = countChar(str, char); + expect(count).toBe(1); +}); + +// Scenario: Mixed string +test("should count occurrences in a mixed string", () => { + const str = "banana"; + const char = "a"; + const count = countChar(str, char); + expect(count).toBe(3); +}); + +// Scenario: Empty string +test("should return 0 for empty string", () => { + const str = ""; + const char = "a"; + const count = countChar(str, char); + expect(count).toBe(0); +}); + +// Scenario: Case sensitivity +test("should be case sensitive", () => { + const str = "AaAa"; + const char = "a"; + const count = countChar(str, char); + expect(count).toBe(2); +}); + // Scenario: No Occurrences // Given the input string `str`, // And a character `char` that does not exist within `str`. From 38fd40818991a1db3b3d6b198a612d0b11f2e7a4 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Sat, 6 Jun 2026 16:12:34 +0100 Subject: [PATCH 31/45] Update count.js --- Sprint-3/2-practice-tdd/count.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index e5d67f4ba2..8e797d6b3c 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,5 @@ function countChar(stringOfCharacters, findCharacter) { - return text.split('').filter(x => x === char).length + return stringOfCharacters.split('').filter(x => x === findCharacter).length } module.exports = countChar; From 802acdf2a665f923533c93552731f3256eb790a5 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Sat, 13 Jun 2026 11:26:29 +0100 Subject: [PATCH 32/45] Update get-ordinal-number.js --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db13..bce5234076 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,23 @@ function getOrdinalNumber(num) { - return "1st"; + const asString = String(n); + + if (n === 0) { + return "0"; + } else if ( + asString.endsWith("11") || + asString.endsWith("12") || + asString.endsWith("13") + ) { + return asString + "th"; + } else if (asString.endsWith("1")) { + return asString + "st"; + } else if (asString.endsWith("2")) { + return asString + "nd"; + } else if (asString.endsWith("3")) { + return asString + "rd"; + } else { + return asString + "th"; + } } module.exports = getOrdinalNumber; From bc421feccb350de9fa1471f5af947e9b48e7db3d Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Sat, 13 Jun 2026 11:28:42 +0100 Subject: [PATCH 33/45] Update get-ordinal-number.test.js --- .../2-practice-tdd/get-ordinal-number.test.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js index adfa58560f..682ee9969b 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -18,3 +18,42 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(131)).toEqual("131st"); }); + +const getOrdinalNumber = require("./get-ordinal-number"); + +/// Case 2: Numbers ending with 2 (but not 12) +test("should append 'nd' for numbers ending with 2, except those ending with 12", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(22)).toEqual("22nd"); + expect(getOrdinalNumber(102)).toEqual("102nd"); +}); + +// Case 3: Numbers ending with 3 (but not 13) +test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(23)).toEqual("23rd"); + expect(getOrdinalNumber(103)).toEqual("103rd"); +}); + +// Case 4: Numbers ending with 11, 12, or 13 should always use 'th' +test("should append 'th' for numbers ending with 11, 12, or 13", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); + expect(getOrdinalNumber(111)).toEqual("111th"); + expect(getOrdinalNumber(212)).toEqual("212th"); + expect(getOrdinalNumber(313)).toEqual("313th"); +}); + +// Case 5: All other numbers should use 'th' +test("should append 'th' for numbers that do not end in 1, 2, or 3", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(20)).toEqual("20th"); + expect(getOrdinalNumber(99)).toEqual("99th"); +}); + +// Case 6: Zero should return '0' +test("should return '0' when the input is zero", () => { + expect(getOrdinalNumber(0)).toEqual("0"); +}); From 13d146012596e4bc5be840a6d2b1856e8f7a991b Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Sat, 13 Jun 2026 11:41:46 +0100 Subject: [PATCH 34/45] Update get-ordinal-number.js --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index bce5234076..9929fb450f 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,5 @@ function getOrdinalNumber(num) { - const asString = String(n); + const asString = String(num); if (n === 0) { return "0"; From 99731eac15395144678a52ae1deca196c59c8e8f Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Sat, 13 Jun 2026 11:45:49 +0100 Subject: [PATCH 35/45] Update get-ordinal-number.js --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index 9929fb450f..26ff6c79cd 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,7 +1,7 @@ function getOrdinalNumber(num) { const asString = String(num); - if (n === 0) { + if (num === 0) { return "0"; } else if ( asString.endsWith("11") || From 5565323592588ead82c19781c9a63c049c5067fb Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Sat, 13 Jun 2026 11:48:07 +0100 Subject: [PATCH 36/45] Update get-ordinal-number.js From d2470e2b68657dd6a3e3404568fa42cabfc28550 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Sat, 13 Jun 2026 11:49:05 +0100 Subject: [PATCH 37/45] Update get-ordinal-number.test.js --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js index 682ee9969b..367665ef96 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -19,8 +19,6 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(131)).toEqual("131st"); }); -const getOrdinalNumber = require("./get-ordinal-number"); - /// Case 2: Numbers ending with 2 (but not 12) test("should append 'nd' for numbers ending with 2, except those ending with 12", () => { expect(getOrdinalNumber(2)).toEqual("2nd"); From 7d82706770392fbb73e9e7a8ac628b22338d79a5 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Sat, 13 Jun 2026 12:07:21 +0100 Subject: [PATCH 38/45] Update repeat-str.js --- Sprint-3/2-practice-tdd/repeat-str.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 3838c7b003..6d8d773451 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,5 +1,5 @@ function repeatStr() { - return "hellohellohello"; + return string.repeat(repeat); } module.exports = repeatStr; From 99949301432faab3234433709cdbc556c5735055 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Sat, 13 Jun 2026 12:08:15 +0100 Subject: [PATCH 39/45] Update repeat-str.js --- Sprint-3/2-practice-tdd/repeat-str.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 6d8d773451..2575f1f48c 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,4 +1,4 @@ -function repeatStr() { +function repeatStr(n,s) { return string.repeat(repeat); } From c8b67c439ad33392cb7d4bd289399e707ba68d96 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Sat, 13 Jun 2026 13:29:22 +0100 Subject: [PATCH 40/45] Update repeat-str.js --- Sprint-3/2-practice-tdd/repeat-str.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 2575f1f48c..7850fb691a 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,5 +1,5 @@ -function repeatStr(n,s) { - return string.repeat(repeat); +function repeatStr(str, count) { + return str.repeat(count); } module.exports = repeatStr; From 5ee586b876d56ae2842c64484424718bd3e0ecb8 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Sat, 13 Jun 2026 13:36:55 +0100 Subject: [PATCH 41/45] Update repeat-str.test.js --- Sprint-3/2-practice-tdd/repeat-str.test.js | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index a3fc1196c4..35d46e3539 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -21,12 +21,35 @@ test("should repeat the string count times", () => { // When the repeatStr function is called with these inputs, // Then it should return the original `str` without repetition. +test("should return the original string when count is 1", () => { + const str = "hello"; + const count = 1; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("hello"); +}); + // 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. +test("should return an empty string when count is 0", () => { + const str = "hello"; + const count = 0; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual(""); +}); + // 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. + +test("should throw an error when count is negative", () => { + const str = "hello"; + const count = -2; + + expect(() => { + repeatStr(str, count); + }).toThrow(); +}); From ee47e29023f535038ad0cb9a47614cf2d506e4c3 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Sat, 13 Jun 2026 13:46:12 +0100 Subject: [PATCH 42/45] Update exercise-1.js --- Sprint-3/3-dead-code/exercise-1.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js index 4d09f15fa9..494e241883 100644 --- a/Sprint-3/3-dead-code/exercise-1.js +++ b/Sprint-3/3-dead-code/exercise-1.js @@ -4,10 +4,8 @@ let testName = "Jerry"; const greeting = "hello"; -function sayHello(greeting, name) { - const greetingStr = greeting + ", " + name + "!"; - return `${greeting}, ${name}!`; - console.log(greetingStr); +function sayHello(greeting, name) { + return `${greeting}, ${name}!`; } testName = "Aman"; From 4fed182120f43fbaf4a9bdf956f33cade8f73782 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Sat, 13 Jun 2026 13:49:44 +0100 Subject: [PATCH 43/45] Update exercise-2.js --- Sprint-3/3-dead-code/exercise-2.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js index 56d7887c4c..59b7de688d 100644 --- a/Sprint-3/3-dead-code/exercise-2.js +++ b/Sprint-3/3-dead-code/exercise-2.js @@ -2,12 +2,8 @@ // The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable. const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; -const capitalisedPets = pets.map((pet) => pet.toUpperCase()); -const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); -function logPets(petsArr) { - petsArr.forEach((pet) => console.log(pet)); -} +const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); function countAndCapitalisePets(petsArr) { const petCount = {}; @@ -25,4 +21,4 @@ function countAndCapitalisePets(petsArr) { const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH); -console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log + From 9738b166e459d926f574c905230efca0c2fc5b43 Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Sat, 13 Jun 2026 15:21:43 +0100 Subject: [PATCH 44/45] Delete Sprint-2 directory --- Sprint-2/1-key-errors/0.js | 23 ----------- 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 | 24 ----------- Sprint-2/2-mandatory-debug/2.js | 36 ---------------- Sprint-2/3-mandatory-implement/1-bmi.js | 24 ----------- Sprint-2/3-mandatory-implement/2-cases.js | 22 ---------- Sprint-2/3-mandatory-implement/3-to-pounds.js | 36 ---------------- Sprint-2/4-mandatory-interpret/time-format.js | 38 ----------------- Sprint-2/5-stretch-extend/format-time.js | 25 ----------- Sprint-2/readme.md | 41 ------------------- 12 files changed, 354 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 diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js deleted file mode 100644 index f0eb49e34b..0000000000 --- a/Sprint-2/1-key-errors/0.js +++ /dev/null @@ -1,23 +0,0 @@ -// Predict and explain first... -// =============> write your prediction here - -// 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; -} - -// =============> write your explanation here - -// Your need to delete "let ". That's just for making a new variables. You want assignment. - -// =============> write your new code here - -function capitalise(str) { - str = `${str[0].toUpperCase()}${str.slice(1)}`; - return str; -} - -console.log(capitalise("hello")); diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js deleted file mode 100644 index db1f0c33f4..0000000000 --- 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? -// =============> write your prediction here - -// 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 - -// You need to pass the value in, not declare it within the function. The syntax is wrong. - -// 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)); diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js deleted file mode 100644 index 5774cb268f..0000000000 --- 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 - -// num is not defined - -function square(3) { - return num * num; -} - -// =============> write the error message here - -// SyntaxError: Unexpected token (1:16) - -// =============> explain this error message here - -// You can't feed the value in there. You need to call it from outside the function. JS thinks it's a variable name which isn't allowed to start with a number. - -// Finally, correct the code to fix the problem - -// =============> write your new code here - -function square(num) { - return num * num; -} - -console.log(square(2)) - - diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js deleted file mode 100644 index d0602130d6..0000000000 --- a/Sprint-2/2-mandatory-debug/0.js +++ /dev/null @@ -1,24 +0,0 @@ -// Predict and explain first... - -// =============> write your prediction here - -// 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 - -// Nothing is returned in the function but rather logged to the console - -// 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)}`); diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js deleted file mode 100644 index 1ee394f405..0000000000 --- a/Sprint-2/2-mandatory-debug/1.js +++ /dev/null @@ -1,24 +0,0 @@ -// Predict and explain first... -// =============> write your prediction here - -// It returns blank since it doesn't know what it's returning - -function sum(a, b) { - return; - a + b; -} - -console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); - -// =============> write your explanation here - - return a + b is supposed to be on one line. "return;" just returns nothing - -// 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 eb585443ad..0000000000 --- a/Sprint-2/2-mandatory-debug/2.js +++ /dev/null @@ -1,36 +0,0 @@ -// Predict and explain first... - -// Predict the output of the following code: -// =============> Write your prediction here - -// It's putting the answer to everything as 3, the last digit of the contant. - -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 - -// My prediction was correct. - -// Explain why the output is the way it is -// =============> write your explanation here - -// function getLastDigit() should have "theNumber" or something in its brackets. It's getting the last digit of the constant as the answer to everything at the moment. - -// Finally, correct the code to fix the problem -// =============> write your new code here - -function getLastDigit(num) { - return num.toString().slice(-1); -} - -// This program should tell the user the last digit of each number. -// Explain why getLastDigit is not working properly - correct the problem 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 1ade2f874d..0000000000 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ /dev/null @@ -1,24 +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 - function calculateBMI(weight, height) { - return (weight/(height**2)).toFixed(1) -} - -console.log (calculateBMI(70, 1.73)); -} diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js deleted file mode 100644 index 16eb4cea9d..0000000000 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ /dev/null @@ -1,22 +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 - -function snakeCase(toConvert) { - return toConvert.replace(" ", "_").toUpperCase(); -} - -console.log(snakeCase("hello there")); 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 eea021b2d3..0000000000 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ /dev/null @@ -1,36 +0,0 @@ -// 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 - -function calculateBMI(penceString) { - - // remove last character - const penceStringWithoutTrailingP = penceString.substring( - 0, - penceString.length - 1 - ); - - // pad to the length of three - const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); - - // remove the last two characters - const pounds = paddedPenceNumberString.substring( - 0, - paddedPenceNumberString.length - 2 - ); - - // get last two characters and pad to two if needed - const pence = paddedPenceNumberString - .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); - - console.log(`£${pounds}.${pence}`); - -} - -console.log(calculateBMI("456p")) -console.log(calculateBMI("545747p")) -console.log(calculateBMI("1p")) 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 3cf66a1e98..0000000000 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ /dev/null @@ -1,38 +0,0 @@ -function pad(num) { - let numString = num.toString(); - while (numString.length < 2) { - numString = "0" + numString; - } - return numString; -} - -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)}`; -} - -// 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? -// =============> 3 - -// 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? -// =============> 0 - -// c) What is the return value of pad is called for the first time? -// =============> "00" - -// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> 1 - Remaining seconds is calculated first with %60 and 1 is what's left over. - -// e) What is the return value of pad when it is called for the last time in this program? Explain your answer -// =============> "01" - now it's 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 32a32e66b8..0000000000 --- a/Sprint-2/5-stretch-extend/format-time.js +++ /dev/null @@ -1,25 +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}` -); diff --git a/Sprint-2/readme.md b/Sprint-2/readme.md deleted file mode 100644 index 44c118e338..0000000000 --- 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. From 524720a6d6ad731cf413facaca7ceb4a60a8f62c Mon Sep 17 00:00:00 2001 From: joanne342 <130585013+joanne342@users.noreply.github.com> Date: Sat, 13 Jun 2026 15:22:57 +0100 Subject: [PATCH 45/45] Delete Sprint-3 directory --- .../1-implement-and-rewrite-tests/README.md | 47 ---------- .../implement/1-get-angle-type.js | 57 ------------ .../implement/2-is-proper-fraction.js | 34 ------- .../implement/3-get-card-value.js | 77 ---------------- .../1-get-angle-type.test.js | 56 ----------- .../2-is-proper-fraction.test.js | 39 -------- .../3-get-card-value.test.js | 70 -------------- .../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 | 64 ------------- Sprint-3/2-practice-tdd/get-ordinal-number.js | 23 ----- .../2-practice-tdd/get-ordinal-number.test.js | 57 ------------ Sprint-3/2-practice-tdd/repeat-str.js | 5 - Sprint-3/2-practice-tdd/repeat-str.test.js | 55 ----------- Sprint-3/3-dead-code/README.md | 9 -- Sprint-3/3-dead-code/exercise-1.js | 15 --- Sprint-3/3-dead-code/exercise-2.js | 24 ----- 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, 861 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 4658c9423a..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 implementation and your tests to cover the cases the function should fulfil. - -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 8c14be696e..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ /dev/null @@ -1,57 +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) { - if (angle > 0 && angle < 90) { - return "Acute angle"; - } - - if (angle === 90) { - return "Right angle"; - } - - if (angle > 90 && angle < 180) { - return "Obtuse angle"; - } - - if (angle === 180) { - return "Straight angle"; - } - - if (angle > 180 && angle < 360) { - return "Reflex angle"; - } - - return "Invalid angle"; -} - -// The line below allows us to load the getAngleType function into tests in other files. -// This will be useful in the "rewrite tests with jest" step. -module.exports = getAngleType; - -// This helper function is written to make our assertions easier to read. -// If the actual output matches the target output, the test will pass -function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); -} - -// TODO: Write tests to cover all cases, including boundary and invalid cases. -// Example: Identify Right Angles -const right = getAngleType(90); -assertEquals(right, "Right angle"); diff --git a/Sprint-3/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 07f6d0e10e..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ /dev/null @@ -1,34 +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) { - if (denominator === 0) return false; - return Math.abs(numerator) < Math.abs(denominator); -} - -// The line below allows us to load the isProperFraction function into tests in other files. -// This will be useful in the "rewrite tests with jest" step. -module.exports = isProperFraction; - -// Here's our helper again -function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); -} - -// 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 a00afcc3c7..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ /dev/null @@ -1,77 +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) { - if (card.length < 2 || card.length > 3) { - throw new Error("Invalid card"); - } - - const suit = card.slice(-1); - const rank = card.slice(0, -1); - - if (!"♥♦♣♠".includes(suit)) { - throw new Error("Invalid card"); - } - - if (/^[2-9]$/.test(rank) || rank === "10") { - return Number(rank); - } - - if (["J", "Q", "K"].includes(rank)) { - return 10; - } - - if (rank === "A") { - return 11; - } - - 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. -// 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) { - console.log("Error thrown for invalid card 🎉"); -} - -// 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 985951882b..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js +++ /dev/null @@ -1,56 +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 === 90)`, () => { - // Test right angle - expect(getAngleType(90)).toEqual("Right angle"); -}); - -// Case 3: Obtuse angles - -test(`should return "Obtuse angle" when (90 < angle < 180)`, () => { - // Test various obtuse angles, including boundary cases - expect(getAngleType(91)).toEqual("Obtuse angle"); - expect(getAngleType(145)).toEqual("Obtuse angle"); - expect(getAngleType(99)).toEqual("Obtuse angle"); -}); - -// Case 4: Straight angle - -test(`should return "Straight angle" when (angle === 180)`, () => { - // Test straight angle - expect(getAngleType(180)).toEqual("Straight angle"); -}); - -// Case 5: Reflex angles - -test(`should return "Reflex angle" when (180 < angle < 360)`, () => { - // Test various reflex angles, including boundary cases - expect(getAngleType(191)).toEqual("Reflex angle"); - expect(getAngleType(245)).toEqual("Reflex angle"); - expect(getAngleType(199)).toEqual("Reflex angle"); -}); - -// Case 6: Invalid angles - -test(`should return "Invalid angle" when (angle < 0 || angle > 360)`, () => { - // Test various invalid angles, including boundary cases - expect(getAngleType(-1)).toEqual("Invalid angle"); - expect(getAngleType(395)).toEqual("Invalid angle"); - expect(getAngleType(389)).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 7b0b9c26cd..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ /dev/null @@ -1,39 +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); -}); - -test("1/2 is proper", () => { - expect(isProperFraction(1, 2)).toBe(true); -}); - -test("3/2 is improper", () => { - expect(isProperFraction(3, 2)).toBe(false); -}); - -test("0/5 is proper", () => { - expect(isProperFraction(0, 5)).toBe(true); -}); - -test("denominator 0 is invalid", () => { - expect(isProperFraction(1, 0)).toBe(false); -}); - -test("-1/2 is proper", () => { - expect(isProperFraction(-1, 2)).toBe(true); -}); - -test("1/-2 is proper", () => { - expect(isProperFraction(1, -2)).toBe(true); -}); - -test("-3/2 is improper", () => { - expect(isProperFraction(-3, 2)).toBe(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 ce5b3770fc..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ /dev/null @@ -1,70 +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); -}); - -// Number cards -test("Should return 2 for 2♣", () => { - expect(getCardValue("2♣")).toEqual(2); -}); - -test("Should return 10 for 10♥", () => { - expect(getCardValue("10♥")).toEqual(10); -}); - -// Face cards -test("Should return 10 for J♦", () => { - expect(getCardValue("J♦")).toEqual(10); -}); - -test("Should return 10 for Q♠", () => { - expect(getCardValue("Q♠")).toEqual(10); -}); - -test("Should return 10 for K♣", () => { - expect(getCardValue("K♣")).toEqual(10); -}); - -// ========================================================= -// INVALID CARDS -// ========================================================= - -test("Should throw an error for 1♠", () => { - expect(() => getCardValue("1♠")).toThrowError(); -}); - -test("Should throw an error for A?", () => { - expect(() => getCardValue("A?")).toThrowError(); -}); - -test("Should throw an error for empty string", () => { - expect(() => getCardValue("")).toThrowError(); -}); - -test("Should throw an error for 11♣", () => { - expect(() => getCardValue("11♣")).toThrowError(); -}); - -test("Should throw an error for invalid rank", () => { - expect(() => getCardValue("Z♦")).toThrowError(); -}); - -test("Should throw an error for missing rank", () => { - expect(() => getCardValue("♠")).toThrowError(); -}); - -// 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 8e797d6b3c..0000000000 --- a/Sprint-3/2-practice-tdd/count.js +++ /dev/null @@ -1,5 +0,0 @@ -function countChar(stringOfCharacters, findCharacter) { - return stringOfCharacters.split('').filter(x => x === findCharacter).length -} - -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 254b244d27..0000000000 --- a/Sprint-3/2-practice-tdd/count.test.js +++ /dev/null @@ -1,64 +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 -test("should return 0 when character is not present", () => { - const str = "hello"; - const char = "z"; - const count = countChar(str, char); - expect(count).toBe(0); -}); - -// Scenario: Single Occurrence -test("should count a single occurrence of a character", () => { - const str = "hello"; - const char = "h"; - const count = countChar(str, char); - expect(count).toBe(1); -}); - -// Scenario: Mixed string -test("should count occurrences in a mixed string", () => { - const str = "banana"; - const char = "a"; - const count = countChar(str, char); - expect(count).toBe(3); -}); - -// Scenario: Empty string -test("should return 0 for empty string", () => { - const str = ""; - const char = "a"; - const count = countChar(str, char); - expect(count).toBe(0); -}); - -// Scenario: Case sensitivity -test("should be case sensitive", () => { - const str = "AaAa"; - const char = "a"; - const count = countChar(str, char); - expect(count).toBe(2); -}); - -// 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 26ff6c79cd..0000000000 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ /dev/null @@ -1,23 +0,0 @@ -function getOrdinalNumber(num) { - const asString = String(num); - - if (num === 0) { - return "0"; - } else if ( - asString.endsWith("11") || - asString.endsWith("12") || - asString.endsWith("13") - ) { - return asString + "th"; - } else if (asString.endsWith("1")) { - return asString + "st"; - } else if (asString.endsWith("2")) { - return asString + "nd"; - } else if (asString.endsWith("3")) { - return asString + "rd"; - } else { - return asString + "th"; - } -} - -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 367665ef96..0000000000 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ /dev/null @@ -1,57 +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"); -}); - -/// Case 2: Numbers ending with 2 (but not 12) -test("should append 'nd' for numbers ending with 2, except those ending with 12", () => { - expect(getOrdinalNumber(2)).toEqual("2nd"); - expect(getOrdinalNumber(22)).toEqual("22nd"); - expect(getOrdinalNumber(102)).toEqual("102nd"); -}); - -// Case 3: Numbers ending with 3 (but not 13) -test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { - expect(getOrdinalNumber(3)).toEqual("3rd"); - expect(getOrdinalNumber(23)).toEqual("23rd"); - expect(getOrdinalNumber(103)).toEqual("103rd"); -}); - -// Case 4: Numbers ending with 11, 12, or 13 should always use 'th' -test("should append 'th' for numbers ending with 11, 12, or 13", () => { - expect(getOrdinalNumber(11)).toEqual("11th"); - expect(getOrdinalNumber(12)).toEqual("12th"); - expect(getOrdinalNumber(13)).toEqual("13th"); - expect(getOrdinalNumber(111)).toEqual("111th"); - expect(getOrdinalNumber(212)).toEqual("212th"); - expect(getOrdinalNumber(313)).toEqual("313th"); -}); - -// Case 5: All other numbers should use 'th' -test("should append 'th' for numbers that do not end in 1, 2, or 3", () => { - expect(getOrdinalNumber(4)).toEqual("4th"); - expect(getOrdinalNumber(10)).toEqual("10th"); - expect(getOrdinalNumber(20)).toEqual("20th"); - expect(getOrdinalNumber(99)).toEqual("99th"); -}); - -// Case 6: Zero should return '0' -test("should return '0' when the input is zero", () => { - expect(getOrdinalNumber(0)).toEqual("0"); -}); 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 7850fb691a..0000000000 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ /dev/null @@ -1,5 +0,0 @@ -function repeatStr(str, count) { - return str.repeat(count); -} - -module.exports = repeatStr; diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js deleted file mode 100644 index 35d46e3539..0000000000 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ /dev/null @@ -1,55 +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. - -test("should return the original string when count is 1", () => { - const str = "hello"; - const count = 1; - const repeatedStr = repeatStr(str, count); - expect(repeatedStr).toEqual("hello"); -}); - -// 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. - -test("should return an empty string when count is 0", () => { - const str = "hello"; - const count = 0; - const repeatedStr = repeatStr(str, count); - expect(repeatedStr).toEqual(""); -}); - -// 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. - -test("should throw an error when count is negative", () => { - const str = "hello"; - const count = -2; - - expect(() => { - repeatStr(str, count); - }).toThrow(); -}); 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 494e241883..0000000000 --- a/Sprint-3/3-dead-code/exercise-1.js +++ /dev/null @@ -1,15 +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) { - return `${greeting}, ${name}!`; -} - -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 59b7de688d..0000000000 --- a/Sprint-3/3-dead-code/exercise-2.js +++ /dev/null @@ -1,24 +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 petsStartingWithH = pets.filter((pet) => pet[0] === "h"); - -function countAndCapitalisePets(petsArr) { - const petCount = {}; - - petsArr.forEach((pet) => { - const capitalisedPet = pet.toUpperCase(); - if (petCount[capitalisedPet]) { - petCount[capitalisedPet] += 1; - } else { - petCount[capitalisedPet] = 1; - } - }); - return petCount; -} - -const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH); - - 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.