From 8be0a945cb4d04b820f33afb0994f383af6bf484 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Thu, 25 Dec 2025 19:37:46 +0100 Subject: [PATCH 01/52] i declared prediction --- Sprint-2/1-key-errors/0.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..2445d911f 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -10,4 +10,4 @@ function capitalise(str) { } // =============> write your explanation here -// =============> write your new code here +// =============> write your new code here \ No newline at end of file From 15b03d8264c7d8f3d5fd8e20b28b24b817166ecf Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Thu, 25 Dec 2025 19:41:43 +0100 Subject: [PATCH 02/52] i declared percentage conversion --- Sprint-2/1-key-errors/1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..987186f20 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -17,4 +17,4 @@ console.log(decimalNumber); // =============> write your explanation here // Finally, correct the code to fix the problem -// =============> write your new code here +// =============> write your new code here \ No newline at end of file From 021bf84cef6117ca3d15f2f07da19ea6c0cabae7 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Thu, 25 Dec 2025 20:18:36 +0100 Subject: [PATCH 03/52] i fix error problems --- Sprint-2/1-key-errors/2.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..269ab8a3c 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -17,4 +17,3 @@ function square(3) { // =============> write your new code here - From 692c65499ea2a6e58d03a564bc679ef1d9301027 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Thu, 25 Dec 2025 20:21:25 +0100 Subject: [PATCH 04/52] i predict --- Sprint-2/1-key-errors/2.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index 269ab8a3c..8db2f38ce 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,19 +1,14 @@ +// Predict and explain first... -// Predict and explain first BEFORE you run any code... +// =============> write your prediction here -// this function should square any number but instead we're going to get an error - -// =============> write your prediction of the error here - -function square(3) { - return num * num; +function multiply(a, b) { + console.log(a * b); } -// =============> write the error message here +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// =============> explain this error message here +// =============> write your explanation here // Finally, correct the code to fix the problem - -// =============> write your new code here - +// =============> write your new code here \ No newline at end of file From c2d19c18204d1c1825fa146bac61dbaff9813480 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Thu, 25 Dec 2025 20:24:27 +0100 Subject: [PATCH 05/52] sun of function --- Sprint-2/2-mandatory-debug/1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..718468166 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -10,4 +10,4 @@ console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here // Finally, correct the code to fix the problem -// =============> write your new code here +// =============> write your new code here \ No newline at end of file From f5dab8918960b6827257a836e3b118b00f457d3b Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Thu, 25 Dec 2025 20:27:40 +0100 Subject: [PATCH 06/52] i declared the prediction of an output --- Sprint-2/2-mandatory-debug/2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..fdcc23862 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -21,4 +21,4 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`); // =============> write your new code here // This program should tell the user the last digit of each number. -// Explain why getLastDigit is not working properly - correct the problem +// Explain why getLastDigit is not working properly - correct the problem \ No newline at end of file From c75033d915d98eb060620605ab50c91ac30de850 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Thu, 25 Dec 2025 20:32:33 +0100 Subject: [PATCH 07/52] i declared diffrent cases --- Sprint-2/3-mandatory-implement/2-cases.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..9327e98c4 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -13,4 +13,4 @@ // 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 +// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase \ No newline at end of file From 8aeaa412eef98e2aa7b4c029c2c05882e4ed33ee Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Thu, 25 Dec 2025 20:35:02 +0100 Subject: [PATCH 08/52] i declared program written --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..99ce20539 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -3,4 +3,4 @@ // You will need to take this code and turn it into a reusable block of code. // You will need to declare a function called toPounds with an appropriately named parameter. -// You should call this function a number of times to check it works for different inputs +// You should call this function a number of times to check it works for different inputs \ No newline at end of file From 7008404cb7e5d986389cb15ace201ed59c865067 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Thu, 25 Dec 2025 20:37:54 +0100 Subject: [PATCH 09/52] i declared former time display --- Sprint-2/4-mandatory-interpret/time-format.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..f9b0d8570 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -31,4 +31,4 @@ function formatTimeDisplay(seconds) { // =============> write your answer here // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> write your answer here +// =============> write your answer here \ No newline at end of file From 50d5fb45b18398c630e5aab58c8d755a8b058ba3 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Thu, 25 Dec 2025 21:57:09 +0100 Subject: [PATCH 10/52] i declared calculation --- Sprint-2/3-mandatory-implement/1-bmi.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..d2b705b55 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -6,7 +6,7 @@ // 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. +// 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 @@ -15,5 +15,5 @@ // 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 +// return the BMI of someone based off their weight and height } \ No newline at end of file From 01a09def84140c1c713f58bd73a1fcb304d3760e Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Thu, 25 Dec 2025 22:03:06 +0100 Subject: [PATCH 11/52] i declared cuurent output --- Sprint-2/5-stretch-extend/format-time.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..2cfcba511 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -22,4 +22,4 @@ const targetOutput2 = "11:00 pm"; console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` -); +); \ No newline at end of file From 93981cafddaa56e1db26e6904b83bd835f968eb1 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Fri, 26 Dec 2025 13:21:32 +0100 Subject: [PATCH 12/52] i declared string representing --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..16461f05e 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -24,4 +24,18 @@ console.log(`£${pounds}.${pence}`); // Try and describe the purpose / rationale behind each step // To begin, we can start with -// 1. const penceString = "399p": initialises a string variable with the value "399p" +// 1. const penceString = "399p": initialise a string variable with the value "399p" + +// 3. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length -1); +// cleaning the trailing P character. it uses the string´s length minus 1 as the end index for substring(), this leave only the numeric value while drop the last character. + +// 8. const paddedPenceNumberString = penceStringWithoutTrailingP.padStar(3, "0"); Padding- ensure the numeric string is at least three characters long by prepending zeros. +// this is important for separating pounds from pence especially when values is less than 100p + +// 9. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2); Extracting pounds component, this uses substring() +// to take all character from the start (index 0) up to, but not including the last two characters, they are always pence. + +// 14. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); Extracting and formatting price- +// Extracts the pence component (the last two digits) and ensures they are always two digits long by padding the end with a zero if needed (though not needed for "99"). + +// 18. console.log(\£${pounds}.${pence}`);` Output: Format the extracted components into the standard currency display £3.99. \ No newline at end of file From 42bd4f41db0197d00af0865f753358ad8df69860 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Fri, 26 Dec 2025 14:38:26 +0100 Subject: [PATCH 13/52] i declared functions --- Sprint-2/4-mandatory-interpret/time-format.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index f9b0d8570..600040bfc 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -11,7 +11,7 @@ function formatTimeDisplay(seconds) { return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } -// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit +// You will need to play computer with this example - use the Python Visualizer https://pythontutor.com/visualize.html#mode=edit // to help you answer these questions // Questions From 5b14359cd8293535908ca82f00342da473fe15e4 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Fri, 26 Dec 2025 16:29:52 +0100 Subject: [PATCH 14/52] i declared variable --- Sprint-1/1-key-exercises/1-count.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..b8580c502 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -3,4 +3,4 @@ let count = 0; count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 -// Describe what line 3 is doing, in particular focus on what = is doing +// Describe what line 3 is doing, in particular focus on what = is doing \ No newline at end of file From 6b1e71e15ee8c769b06cecfc245db5667c13532e Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Fri, 26 Dec 2025 16:32:16 +0100 Subject: [PATCH 15/52] i declared initails --- Sprint-1/1-key-exercises/2-initials.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f617..673e79791 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -8,4 +8,3 @@ let lastName = "Johnson"; let initials = ``; // https://www.google.com/search?q=get+first+character+of+string+mdn - From 5f7e836bc1536bcaa25119f0146d491e6cdc50d6 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Fri, 26 Dec 2025 16:40:47 +0100 Subject: [PATCH 16/52] i declared filepath variable --- Sprint-1/1-key-exercises/3-paths.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28..3dff4769d 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -15,9 +15,13 @@ const base = filePath.slice(lastSlashIndex + 1); console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable +const dir = filePath.slice(0, lastSlashIndex); + // Create a variable to store the ext part of the variable +const extIndex = base.lastIndexOf("."); +const ext = base.slice(extIndex + 1); -const dir = ; -const ext = ; +console.log(`The directory part is ${dir}`); +console.log(`The extension part is ${ext}`); // https://www.google.com/search?q=slice+mdn \ No newline at end of file From ce69949c18e1dadafd1e39215627fed4367ebb85 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Fri, 26 Dec 2025 16:42:50 +0100 Subject: [PATCH 17/52] i declared math.floor --- Sprint-1/1-key-exercises/4-random.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..91406cd27 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -6,4 +6,4 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // In this exercise, you will need to work out what num represents? // Try breaking down the expression and using documentation to explain what it means // It will help to think about the order in which expressions are evaluated -// Try logging the value of num and running the program several times to build an idea of what the program is doing +// Try logging the value of num and running the program several times to build an idea of what the program is doing \ No newline at end of file From 33872c103d1482ddfce6c788d9b7e999a2d31b14 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Fri, 26 Dec 2025 16:46:09 +0100 Subject: [PATCH 18/52] i declared how to solve problem --- Sprint-1/2-mandatory-errors/0.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..69da8d68a 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 +We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file From 853223864a08122b1f7acd058a2145657c96643b Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Fri, 26 Dec 2025 16:47:34 +0100 Subject: [PATCH 19/52] i declared variable creation --- 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 7a43cbea7..43dac0020 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; -age = age + 1; +age = age + 1; \ No newline at end of file From 0878a26ea63680d0db5c5a3eb754514c9c9fbfa5 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Fri, 26 Dec 2025 16:49:42 +0100 Subject: [PATCH 20/52] i declared error --- 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 e09b89831..b446a4233 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -2,4 +2,4 @@ // what's the error ? console.log(`I was born in ${cityOfBirth}`); -const cityOfBirth = "Bolton"; +const cityOfBirth = "Bolton"; \ No newline at end of file From 63331ef1a9e044633562c1026b0864a913fbfd05 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Fri, 26 Dec 2025 16:50:54 +0100 Subject: [PATCH 21/52] i declared updating expression --- Sprint-1/2-mandatory-errors/3.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..2278c96a9 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -6,4 +6,4 @@ const last4Digits = cardNumber.slice(-4); // Before running the code, make and explain a prediction about why the code won't work // Then run the code and see what error it gives. // Consider: Why does it give this error? Is this what I predicted? If not, what's different? -// Then try updating the expression last4Digits is assigned to, in order to get the correct value +// Then try updating the expression last4Digits is assigned to, in order to get the correct value \ No newline at end of file From a33708d1d3258d2ebe3e0d8aac72bc99eadbbbfe Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Fri, 26 Dec 2025 16:54:07 +0100 Subject: [PATCH 22/52] i declared the clocktime --- 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 21dad8c5d..683baac4f 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 hour12ClockTime = "20:53"; // Changed to start with a letter +const hour24ClockTime = "08:53"; // Also changed for consistency From 77cbd879ff8d04653711e6f91346773e0f23e2a9 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Fri, 26 Dec 2025 16:57:39 +0100 Subject: [PATCH 23/52] i declared instruction --- .../1-percentage-change.js | 24 ++----------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..76f30b5bc 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -1,22 +1,2 @@ -let carPrice = "10,000"; -let priceAfterOneYear = "8,543"; - -carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); - -const priceDifference = carPrice - priceAfterOneYear; -const percentageChange = (priceDifference / carPrice) * 100; - -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 - -// 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? - -// c) Identify all the lines that are variable reassignment statements - -// d) Identify all the lines that are variable declarations - -// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +// 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 From 48d2bd7772d4b6ce4ee1255d87544b962945638d Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Fri, 26 Dec 2025 17:00:39 +0100 Subject: [PATCH 24/52] i declared variable first --- .../3-mandatory-interpret/2-time-format.js | 27 ++----------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..29dce0016 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -1,25 +1,2 @@ -const movieLength = 8784; // length of movie in seconds - -const remainingSeconds = movieLength % 60; -const totalMinutes = (movieLength - remainingSeconds) / 60; - -const remainingMinutes = totalMinutes % 60; -const totalHours = (totalMinutes - remainingMinutes) / 60; - -const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; -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? - -// b) How many function calls are there? - -// c) Using documentation, explain what the expression movieLength % 60 represents -// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators - -// d) Interpret line 4, what does the expression assigned to totalMinutes mean? - -// e) What do you think the variable result represents? Can you think of a better name for this variable? - -// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +const cityOfBirth = "Bolton"; // Declare the variable first +console.log(`I was born in ${cityOfBirth}`); // Now you can use it From d4695a24b010ffa3cdb570116aa6684c632bf13b Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Fri, 26 Dec 2025 17:04:48 +0100 Subject: [PATCH 25/52] i declared working on errors --- Sprint-1/3-mandatory-interpret/2-time-format.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 29dce0016..b446a4233 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -1,2 +1,5 @@ -const cityOfBirth = "Bolton"; // Declare the variable first -console.log(`I was born in ${cityOfBirth}`); // Now you can use it +// 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"; \ No newline at end of file From 82849572761921d45a864497d905cfb57cc830de Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Fri, 26 Dec 2025 17:06:59 +0100 Subject: [PATCH 26/52] i declared first activity --- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 2 +- 1 file changed, 1 insertion(+), 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 76f30b5bc..32ea7fc1b 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.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 +// We don't want the computer to run these 2 lines \ No newline at end of file From a3df74406f562eca5c7743083718e8099754ebf2 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Fri, 26 Dec 2025 17:09:01 +0100 Subject: [PATCH 27/52] i declared totalminutes --- .../3-mandatory-interpret/2-time-format.js | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index b446a4233..85efdba75 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -1,5 +1,25 @@ -// Currently trying to print the string "I was born in Bolton" but it isn't working... -// what's the error ? +const movieLength = 8784; // length of movie in seconds -console.log(`I was born in ${cityOfBirth}`); -const cityOfBirth = "Bolton"; \ No newline at end of file +const remainingSeconds = movieLength % 60; +const totalMinutes = (movieLength - remainingSeconds) / 60; + +const remainingMinutes = totalMinutes % 60; +const totalHours = (totalMinutes - remainingMinutes) / 60; + +const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; +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? + +// b) How many function calls are there? + +// c) Using documentation, explain what the expression movieLength % 60 represents +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators + +// d) Interpret line 4, what does the expression assigned to totalMinutes mean? + +// e) What do you think the variable result represents? Can you think of a better name for this variable? + +// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer \ No newline at end of file From 3e611190a324e08c9049e69781dd1e3fb7c553e7 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Fri, 26 Dec 2025 17:11:22 +0100 Subject: [PATCH 28/52] i declared initialize string --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 16461f05e..43b8f6448 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -24,7 +24,7 @@ console.log(`£${pounds}.${pence}`); // Try and describe the purpose / rationale behind each step // To begin, we can start with -// 1. const penceString = "399p": initialise a string variable with the value "399p" +// 1. const penceString = "399p": initialize a string variable with the value "399p" // 3. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length -1); // cleaning the trailing P character. it uses the string´s length minus 1 as the end index for substring(), this leave only the numeric value while drop the last character. From ee5c6d91ffc014c2112c58f1c5158e63dcaa312c Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Fri, 26 Dec 2025 17:13:01 +0100 Subject: [PATCH 29/52] i declared function alert --- Sprint-1/4-stretch-explore/chrome.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feaf..b0682aecd 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -15,4 +15,4 @@ What effect does calling the `alert` function have? Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. What effect does calling the `prompt` function have? -What is the return value of `prompt`? +What is the return value of `prompt`? \ No newline at end of file From 7820bd067ebd407fdb509a1057f0ab6ad181bbb2 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Fri, 26 Dec 2025 17:19:11 +0100 Subject: [PATCH 30/52] i declared consolelog --- Sprint-1/4-stretch-explore/objects.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56..c0f324774 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -13,4 +13,4 @@ Try also entering `typeof console` Answer the following questions: What does `console` store? -What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? \ No newline at end of file From 7739b5d3f9d2b0aeb906fe6aeac3fc54ccb59c69 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Sat, 10 Jan 2026 14:48:24 +0100 Subject: [PATCH 31/52] I implemented the function of getAngleTypes and run test case by case --- Sprint-3/1-key-implement/1-get-angle-type.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-3/1-key-implement/1-get-angle-type.js b/Sprint-3/1-key-implement/1-get-angle-type.js index 08d1f0cba..861e3f248 100644 --- a/Sprint-3/1-key-implement/1-get-angle-type.js +++ b/Sprint-3/1-key-implement/1-get-angle-type.js @@ -8,8 +8,8 @@ // Then, write the next test! :) Go through this process until all the cases are implemented function getAngleType(angle) { - if (angle === 90) return "Right angle"; - // read to the end, complete line 36, then pass your test here +if (angle === 90) return "Right angle"; +// read to the end, complete line 36, then pass your test here } // we're going to use this helper function to make our assertions easier to read From 8afb4a94b9aa30cec12414f88e498ea274ba8621 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Sat, 10 Jan 2026 14:53:12 +0100 Subject: [PATCH 32/52] I implemented isProperFraction --- Sprint-3/1-key-implement/2-is-proper-fraction.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-3/1-key-implement/2-is-proper-fraction.js b/Sprint-3/1-key-implement/2-is-proper-fraction.js index 91583e941..99fa81e58 100644 --- a/Sprint-3/1-key-implement/2-is-proper-fraction.js +++ b/Sprint-3/1-key-implement/2-is-proper-fraction.js @@ -51,3 +51,4 @@ const equalFraction = isProperFraction(3, 3); // Stretch: // What other scenarios could you test for? + From 0a80e2c8519e383c6b8b49e4b0cfdaa91904e217 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Sat, 10 Jan 2026 14:56:44 +0100 Subject: [PATCH 33/52] I implemented getCardValue --- Sprint-3/1-key-implement/3-get-card-value.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-3/1-key-implement/3-get-card-value.js b/Sprint-3/1-key-implement/3-get-card-value.js index aa1cc9f90..58151b745 100644 --- a/Sprint-3/1-key-implement/3-get-card-value.js +++ b/Sprint-3/1-key-implement/3-get-card-value.js @@ -49,3 +49,4 @@ const fiveofHearts = getCardValue("5♥"); // Given a card with an invalid rank (neither a number nor a recognized face card), // When the function is called with such a card, // Then it should throw an error indicating "Invalid card rank." + From 01d1107873da32fcf102cefbf900baba7aa4ca8f Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Sat, 10 Jan 2026 15:10:53 +0100 Subject: [PATCH 34/52] I provided a function on getAngleType --- Sprint-3/2-mandatory-rewrite/1-get-angle-type.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js index d61254bd7..f4bc1f9ac 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js @@ -15,4 +15,4 @@ function getAngleType(angle) { // Jest uses CommonJS module syntax by default as it's quite old // We will upgrade our approach to ES6 modules in the next course module, so for now // we have just written the CommonJS module.exports syntax for you -module.exports = getAngleType; \ No newline at end of file +module.exports = getAngleType; From b8c9082445e25a557b43299a5fe2e024151f0f13 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Sat, 10 Jan 2026 15:13:15 +0100 Subject: [PATCH 35/52] I provided a getAngleType when required --- Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js index b62827b7c..f2f1d8e8e 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js @@ -22,3 +22,5 @@ test("should identify right angle (90°)", () => { // Case 5: Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, // Then the function should return "Reflex angle" + + From 787ef526a4f239c1b719a0d029dd8e1c3cae8c2f Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Sat, 10 Jan 2026 15:17:40 +0100 Subject: [PATCH 36/52] I provided a getAngleTypetest --- Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js index f2f1d8e8e..7a20c0e34 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js @@ -24,3 +24,4 @@ test("should identify right angle (90°)", () => { // Then the function should return "Reflex angle" + From 51dc2de5fa4b99f8cf5c72630a4ffdffe4b255ce Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Sat, 10 Jan 2026 15:19:11 +0100 Subject: [PATCH 37/52] I generated isProperFraction --- Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js index 9836fe398..89d4bf903 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js @@ -3,4 +3,4 @@ function isProperFraction(numerator, denominator) { // add your completed function from key-implement here } -module.exports = isProperFraction; \ No newline at end of file +module.exports = isProperFraction; From 30083f4baa8d1d563ed5a78f399e9a00bdd82f35 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Sat, 10 Jan 2026 15:21:03 +0100 Subject: [PATCH 38/52] I provided a required isProperFraction --- Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js index ff1cc8173..e33daa3c9 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js @@ -9,3 +9,4 @@ test("should return true for a proper fraction", () => { // Case 3: Identify Negative Fractions: // Case 4: Identify Equal Numerator and Denominator: + From 45f285cffc643888a73f756b3a49e885f40d93e8 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Sat, 10 Jan 2026 15:22:32 +0100 Subject: [PATCH 39/52] I generated a getCardValue --- Sprint-3/2-mandatory-rewrite/3-get-card-value.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js index 0d95d3736..328773567 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js @@ -2,4 +2,4 @@ function getCardValue(card) { // replace with your code from key-implement return 11; } -module.exports = getCardValue; \ No newline at end of file +module.exports = getCardValue; From 8b93a1d9849f61c6ed5c03327008a09589727a14 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Sat, 10 Jan 2026 15:23:50 +0100 Subject: [PATCH 40/52] I provided a required getCardValue --- Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js index 03a8e2f34..9f8e6d332 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js @@ -9,3 +9,4 @@ test("should return 11 for Ace of Spades", () => { // Case 3: Handle Face Cards (J, Q, K): // Case 4: Handle Ace (A): // Case 5: Handle Invalid Cards: + From 743af28381436172adb80b0b2aae6e13422ad766 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Sat, 10 Jan 2026 15:29:07 +0100 Subject: [PATCH 41/52] I provided a countcharater --- Sprint-3/3-mandatory-practice/implement/count.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/3-mandatory-practice/implement/count.js b/Sprint-3/3-mandatory-practice/implement/count.js index fce249650..fefebd4ea 100644 --- a/Sprint-3/3-mandatory-practice/implement/count.js +++ b/Sprint-3/3-mandatory-practice/implement/count.js @@ -2,4 +2,4 @@ function countChar(stringOfCharacters, findCharacter) { return 5 } -module.exports = countChar; \ No newline at end of file +module.exports = countChar; From ce3b1a6c7017d34dd2ec6e29ff7cf6dc6e1c20fe Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Sat, 10 Jan 2026 15:30:42 +0100 Subject: [PATCH 42/52] I provided a required countchar --- Sprint-3/3-mandatory-practice/implement/count.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-3/3-mandatory-practice/implement/count.test.js b/Sprint-3/3-mandatory-practice/implement/count.test.js index 42baf4b4b..943bbf027 100644 --- a/Sprint-3/3-mandatory-practice/implement/count.test.js +++ b/Sprint-3/3-mandatory-practice/implement/count.test.js @@ -22,3 +22,4 @@ test("should count multiple occurrences of a character", () => { // And a character char that does not exist within the case-sensitive str, // When the function is called with these inputs, // Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str. + From 4109e2ee37dead499462c826c7dbde9776262338 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Sat, 10 Jan 2026 15:32:15 +0100 Subject: [PATCH 43/52] I provided a getOrdinalNumber --- Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js index 24f528b0d..2aa3e8e93 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js @@ -2,4 +2,4 @@ function getOrdinalNumber(num) { return "1st"; } -module.exports = getOrdinalNumber; \ No newline at end of file +module.exports = getOrdinalNumber; From ea53d0aee9faa42fa2f6fee81fd8c2defda4d414 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Sat, 10 Jan 2026 15:33:46 +0100 Subject: [PATCH 44/52] I provided a required getOrdinalNumber --- .../3-mandatory-practice/implement/get-ordinal-number.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js index 6d55dfbb4..8a23ca998 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js @@ -11,3 +11,4 @@ const getOrdinalNumber = require("./get-ordinal-number"); test("should return '1st' for 1", () => { expect(getOrdinalNumber(1)).toEqual("1st"); }); + From f4a3d6d19a0d2d014ecfde5a1f0376c2e49752c1 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Sat, 10 Jan 2026 15:35:34 +0100 Subject: [PATCH 45/52] I repeat a function --- Sprint-3/3-mandatory-practice/implement/repeat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.js b/Sprint-3/3-mandatory-practice/implement/repeat.js index 621f9bd35..ae0379e1d 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.js @@ -2,4 +2,4 @@ function repeat() { return "hellohellohello"; } -module.exports = repeat; \ No newline at end of file +module.exports = repeat; From 0a7170fa528fd49bd2b60bf183bbb70d8211445d Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Sat, 10 Jan 2026 15:36:44 +0100 Subject: [PATCH 46/52] i repeated a test function --- Sprint-3/3-mandatory-practice/implement/repeat.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.test.js b/Sprint-3/3-mandatory-practice/implement/repeat.test.js index 8a4ab42ef..9da127be0 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.test.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.test.js @@ -30,3 +30,4 @@ test("should repeat the string count times", () => { // Given a target string str and a negative integer count, // When the repeat function is called with these inputs, // Then it should throw an error or return an appropriate error message, as negative counts are not valid. + From 482d66c8ccbb17a25e35a7de067dcbec70815c67 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Sat, 10 Jan 2026 15:38:06 +0100 Subject: [PATCH 47/52] I provided a credit card --- Sprint-3/4-stretch-investigate/card-validator.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-3/4-stretch-investigate/card-validator.md b/Sprint-3/4-stretch-investigate/card-validator.md index e39c6ace6..2b265c977 100644 --- a/Sprint-3/4-stretch-investigate/card-validator.md +++ b/Sprint-3/4-stretch-investigate/card-validator.md @@ -33,3 +33,4 @@ These are the requirements your project needs to fulfill: - Return a boolean from the function to indicate whether the credit card number is valid. Good luck! + From f6f2fa4dee74835b9fabd67f48a59fbe5ea738b9 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Sat, 10 Jan 2026 15:39:45 +0100 Subject: [PATCH 48/52] I find a function --- Sprint-3/4-stretch-investigate/find.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-3/4-stretch-investigate/find.js b/Sprint-3/4-stretch-investigate/find.js index c7e79a2f2..dcc3e6bea 100644 --- a/Sprint-3/4-stretch-investigate/find.js +++ b/Sprint-3/4-stretch-investigate/find.js @@ -23,3 +23,4 @@ console.log(find("code your future", "z")); // 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? + From 940de781f9cfd2d2062dd10073a400d47df7fc82 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Sat, 10 Jan 2026 15:41:07 +0100 Subject: [PATCH 49/52] I provided a passwordvalidator --- Sprint-3/4-stretch-investigate/password-validator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/4-stretch-investigate/password-validator.js b/Sprint-3/4-stretch-investigate/password-validator.js index b55d527db..12dd1accf 100644 --- a/Sprint-3/4-stretch-investigate/password-validator.js +++ b/Sprint-3/4-stretch-investigate/password-validator.js @@ -3,4 +3,4 @@ function passwordValidator(password) { } -module.exports = passwordValidator; \ No newline at end of file +module.exports = passwordValidator; From 1a5ffff3194f0d34caea21feb9f4ec0d8f341762 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Sat, 10 Jan 2026 15:57:55 +0100 Subject: [PATCH 50/52] I provided password validation --- Sprint-3/4-stretch-investigate/password-validator.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/4-stretch-investigate/password-validator.test.js b/Sprint-3/4-stretch-investigate/password-validator.test.js index 8fa3089d6..5909192b6 100644 --- a/Sprint-3/4-stretch-investigate/password-validator.test.js +++ b/Sprint-3/4-stretch-investigate/password-validator.test.js @@ -23,4 +23,4 @@ test("password has at least 5 characters", () => { // Assert expect(result).toEqual(true); } -); \ No newline at end of file +); From 1d3def6d0ec1cd7ea569447230d0759384b69c5a Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Wed, 28 Jan 2026 09:48:01 +0100 Subject: [PATCH 51/52] implement getAngleType, ProperFraction and getCardValue --- Sprint-3/1-key-implement/1-get-angle-type.js | 32 ++++++++++++++----- .../1-key-implement/2-is-proper-fraction.js | 1 + Sprint-3/1-key-implement/3-get-card-value.js | 22 ++++++++++++- .../2-mandatory-rewrite/1-get-angle-type.js | 10 ++---- .../2-is-proper-fraction.js | 5 +++ .../2-mandatory-rewrite/3-get-card-value.js | 28 +++++++++++++--- 6 files changed, 76 insertions(+), 22 deletions(-) diff --git a/Sprint-3/1-key-implement/1-get-angle-type.js b/Sprint-3/1-key-implement/1-get-angle-type.js index 861e3f248..26a76e429 100644 --- a/Sprint-3/1-key-implement/1-get-angle-type.js +++ b/Sprint-3/1-key-implement/1-get-angle-type.js @@ -8,8 +8,14 @@ // Then, write the next test! :) Go through this process until all the cases are implemented function getAngleType(angle) { -if (angle === 90) return "Right angle"; -// read to the end, complete line 36, then pass your test here + if (angle === 90) return "Right angle"; + if (angle < 90) return ("Acute angle"); + if (angle < 180) return ("Obtuse Angles"); + if (angle === 180) return ("Straight Angles"); + if (angle > 180 && angle < 360) return ("Reflex Angles"); + + // read to the end, complete line 36, then pass your test here +return undefined } // we're going to use this helper function to make our assertions easier to read @@ -30,27 +36,37 @@ function assertEquals(actualOutput, targetOutput) { // Case 1: Identify Right Angles: // When the angle is exactly 90 degrees, // Then the function should return "Right angle" -const right = getAngleType(90); -assertEquals(right, "Right angle"); +const a = getAngleType(90); +assertEquals(a, "Right angle"); // Case 2: Identify Acute Angles: // When the angle is less than 90 degrees, // Then the function should return "Acute angle" -const acute = getAngleType(45); -assertEquals(acute, "Acute angle"); +const b = getAngleType(45); +assertEquals(b, "Acute angle"); + // Case 3: Identify Obtuse Angles: // When the angle is greater than 90 degrees and less than 180 degrees, // Then the function should return "Obtuse angle" -const obtuse = getAngleType(120); +const c = getAngleType(120); // ====> write your test here, and then add a line to pass the test in the function above +assertEquals(c, "Obtuse Angles") // Case 4: Identify Straight Angles: // When the angle is exactly 180 degrees, // Then the function should return "Straight angle" // ====> write your test here, and then add a line to pass the test in the function above +const d = getAngleType(180); +assertEquals(d, "Straight Angles") + // Case 5: Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, // Then the function should return "Reflex angle" -// ====> write your test here, and then add a line to pass the test in the function above \ No newline at end of file +// ====> write your test here, and then add a line to pass the test in the function aboves +const e = getAngleType(300) +assertEquals(e, "Reflex Angles") + + + diff --git a/Sprint-3/1-key-implement/2-is-proper-fraction.js b/Sprint-3/1-key-implement/2-is-proper-fraction.js index 99fa81e58..0ec3272df 100644 --- a/Sprint-3/1-key-implement/2-is-proper-fraction.js +++ b/Sprint-3/1-key-implement/2-is-proper-fraction.js @@ -52,3 +52,4 @@ const equalFraction = isProperFraction(3, 3); // Stretch: // What other scenarios could you test for? + diff --git a/Sprint-3/1-key-implement/3-get-card-value.js b/Sprint-3/1-key-implement/3-get-card-value.js index 58151b745..d920f84b9 100644 --- a/Sprint-3/1-key-implement/3-get-card-value.js +++ b/Sprint-3/1-key-implement/3-get-card-value.js @@ -8,8 +8,15 @@ // write one test at a time, and make it pass, build your solution up methodically // just make one change at a time -- don't rush -- programmers are deep and careful thinkers function getCardValue(card) { + const rank = card.slice(0, -1); // Extract rank by removing the last character (suit) if (rank === "A") return 11; -} + if (["K", "Q", "J", "10"].includes(rank)) return 10; + const numericValue = parseInt(rank, 10); + if (numericValue >= 2 && numericValue <= 9) return numericValue; + + throw new Error("Invalid card rank."); + } + // You need to write assertions for your function to check it works in different cases // we're going to use this helper function to make our assertions easier to read @@ -34,19 +41,32 @@ assertEquals(aceofSpades, 11); // Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5). const fiveofHearts = getCardValue("5♥"); // ====> write your test here, and then add a line to pass the test in the function above +assertEquals(fiveofHearts, 5); // Handle Face Cards (J, Q, K): // Given a card with a rank of "10," "J," "Q," or "K", // When the function is called with such a card, // Then it should return the value 10, as these cards are worth 10 points each in blackjack. +const kingofDiamonds = getCardValue("K♦"); +// ====> write your test here, and then add a line to pass the test in the function above +assertEquals(kingofDiamonds, 10); // Handle Ace (A): // Given a card with a rank of "A", // When the function is called with an Ace, // Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack. +const aceofClubs = getCardValue("A♣"); +// ====> write your test here, and then add a line to pass the test in the function above +assertEquals(aceofClubs, 11); + // Handle Invalid Cards: // Given a card with an invalid rank (neither a number nor a recognized face card), // When the function is called with such a card, // Then it should throw an error indicating "Invalid card rank." +try{ + getCardValue( "X♥") +}catch(e){ + assertEquals(e.message, "Invalid card rank.") +} diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js index f4bc1f9ac..9699ddfc7 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js @@ -2,17 +2,11 @@ function getAngleType(angle) { if (angle === 90) return "Right angle"; // replace with your completed function from key-implement -} - - - - - - - // Don't get bogged down in this detail // Jest uses CommonJS module syntax by default as it's quite old // We will upgrade our approach to ES6 modules in the next course module, so for now // we have just written the CommonJS module.exports syntax for you module.exports = getAngleType; + + diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js index 89d4bf903..46ddce752 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js @@ -1,6 +1,11 @@ function isProperFraction(numerator, denominator) { if (numerator < denominator) return true; // add your completed function from key-implement here + if (numerator > denominator) return false; + if (numerator <= 0 || denominator <= 0) return false; + if (numerator === denominator) return false; + return false; + } module.exports = isProperFraction; diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js index 328773567..d9647ff2a 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js @@ -1,5 +1,23 @@ -function getCardValue(card) { - // replace with your code from key-implement - return 11; -} -module.exports = getCardValue; +const isProperFraction = require("./2-is-proper-fraction"); + +test("should return true for a proper fraction", () => { + expect(isProperFraction(2, 3)).toEqual(true); +}); + +// Case 2: Identify Improper Fractions: +test("should return false for an improper fraction", () => { + expect(isProperFraction(5, 4)).toEqual(false); +}); + + + +// Case 3: Identify Negative Fractions: +test("should return false for a negative fraction", () => { + expect(isProperFraction(-2, 3)).toEqual(true); +}); + + +// Case 4: Identify Equal Numerator and Denominator: +test("should return false when numerator equals denominator", () => { + expect(isProperFraction(4, 4)).toEqual(false); +}); From 42de7a6dba09e9794d63c88ebce8ca9c594c2b55 Mon Sep 17 00:00:00 2001 From: Gbemisola Date: Wed, 28 Jan 2026 10:04:00 +0100 Subject: [PATCH 52/52] implement getOrdinalNumber, Repeat, PasswordValidator --- .../2-mandatory-rewrite/1-get-angle-type.js | 14 ++++- .../1-get-angle-type.test.js | 16 +++++- .../2-is-proper-fraction.test.js | 15 ++++- .../2-mandatory-rewrite/3-get-card-value.js | 34 ++++------- .../3-get-card-value.test.js | 19 ++++++- .../3-mandatory-practice/implement/count.js | 23 +++++++- .../implement/count.test.js | 11 ++++ .../implement/get-ordinal-number.js | 15 ++++- .../implement/get-ordinal-number.test.js | 19 ++++++- .../3-mandatory-practice/implement/repeat.js | 12 +++- .../implement/repeat.test.js | 12 ++++ Sprint-3/4-stretch-investigate/find.js | 15 ++++- .../password-validator.js | 15 ++++- .../password-validator.test.js | 56 ++++++++++++++++++- 14 files changed, 230 insertions(+), 46 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js index 9699ddfc7..21259279c 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js @@ -1,6 +1,16 @@ function getAngleType(angle) { if (angle === 90) return "Right angle"; - // replace with your completed function from key-implement + if (angle < 90) return "Acute angle"; + if (angle > 90 && angle < 180) return "Obtuse angle"; + if (angle === 180) return "Straight angle"; + if (angle > 180 && angle < 360) return "Reflex angle"; +} + + + + + + // Don't get bogged down in this detail @@ -8,5 +18,3 @@ function getAngleType(angle) { // We will upgrade our approach to ES6 modules in the next course module, so for now // we have just written the CommonJS module.exports syntax for you module.exports = getAngleType; - - diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js index 7a20c0e34..85cbe3233 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js @@ -10,18 +10,28 @@ test("should identify right angle (90°)", () => { // Case 2: Identify Acute Angles: // When the angle is less than 90 degrees, // Then the function should return "Acute angle" +test("should identify acute angle (<90°)", () => { + expect(getAngleType(45)).toEqual("Acute angle"); +}); + // Case 3: Identify Obtuse Angles: // When the angle is greater than 90 degrees and less than 180 degrees, // Then the function should return "Obtuse angle" +test("should identify obtuse angle (>90° and <180°)", () => { + expect(getAngleType(120)).toEqual("Obtuse angle"); +}); // Case 4: Identify Straight Angles: // When the angle is exactly 180 degrees, // Then the function should return "Straight angle" +test("should identify straight angle (180°)", () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}); // Case 5: Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, // Then the function should return "Reflex angle" - - - +test("should identify reflex angle (>180° and <360°)", () => { + expect(getAngleType(270)).toEqual("Reflex angle"); +}); diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js index e33daa3c9..64aa001c4 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js @@ -4,9 +4,20 @@ test("should return true for a proper fraction", () => { expect(isProperFraction(2, 3)).toEqual(true); }); -// Case 2: Identify Improper Fractions: +// Case 2: Identify Improper Fractions: +test("should return false for an improper fraction", () => { + expect(isProperFraction(5, 4)).toEqual(false); +}); + + // Case 3: Identify Negative Fractions: +test("should return false for a negative fraction", () => { + expect(isProperFraction(-2, 3)).toEqual(true); +}); -// Case 4: Identify Equal Numerator and Denominator: +// Case 4: Identify Equal Numerator and Denominator: +test("should return false when numerator equals denominator", () => { + expect(isProperFraction(4, 4)).toEqual(false); +}); \ No newline at end of file diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js index d9647ff2a..83713e3ad 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js @@ -1,23 +1,11 @@ -const isProperFraction = require("./2-is-proper-fraction"); - -test("should return true for a proper fraction", () => { - expect(isProperFraction(2, 3)).toEqual(true); -}); - -// Case 2: Identify Improper Fractions: -test("should return false for an improper fraction", () => { - expect(isProperFraction(5, 4)).toEqual(false); -}); - - - -// Case 3: Identify Negative Fractions: -test("should return false for a negative fraction", () => { - expect(isProperFraction(-2, 3)).toEqual(true); -}); - - -// Case 4: Identify Equal Numerator and Denominator: -test("should return false when numerator equals denominator", () => { - expect(isProperFraction(4, 4)).toEqual(false); -}); +function getCardValue(card) { + const rank = card.slice(0, -1); // Extract rank by removing the last character (suit) + if (rank === "A") return 11; + if (["K", "Q", "J", "10"].includes(rank)) return 10; + const numericValue = parseInt(rank, 10); + if (numericValue >= 2 && numericValue <= 9) return numericValue; + + throw new Error("Invalid card rank."); + } + +module.exports = getCardValue; \ No newline at end of file diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js index 9f8e6d332..b8f8a2f9e 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js @@ -6,7 +6,24 @@ test("should return 11 for Ace of Spades", () => { }); // Case 2: Handle Number Cards (2-10): +test("should return 7 for Seven of Hearts", () => { + const sevenOfHearts = getCardValue("7♥"); + expect(sevenOfHearts).toEqual(7); + }); // Case 3: Handle Face Cards (J, Q, K): +test("should return 10 for King of Diamonds", () => { + const kingOfDiamonds = getCardValue("K♦"); + expect(kingOfDiamonds).toEqual(10); + }); // Case 4: Handle Ace (A): -// Case 5: Handle Invalid Cards: +test("should return 11 for Ace of Clubs", () => { + const aceOfClubs = getCardValue("A♣"); + expect(aceOfClubs).toEqual(11); + }); +// Case 5: Handle Invalid Cards: +test("should throw an error for invalid card rank", () => { + expect(() => { + getCardValue("1♠"); + }).toThrow("Invalid card rank."); + }); diff --git a/Sprint-3/3-mandatory-practice/implement/count.js b/Sprint-3/3-mandatory-practice/implement/count.js index fefebd4ea..b65bca97f 100644 --- a/Sprint-3/3-mandatory-practice/implement/count.js +++ b/Sprint-3/3-mandatory-practice/implement/count.js @@ -1,5 +1,22 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 -} + let count = 0; + let arrOfChars = stringOfCharacters.split(""); + console.log(arrOfChars) -module.exports = countChar; + arrOfChars.forEach(char => { + if (char === findCharacter) count++ + + }) + + return count; + + + }; + + + console.log( + countChar("abcdefg", "c")); + + + +module.exports = countChar; \ No newline at end of file diff --git a/Sprint-3/3-mandatory-practice/implement/count.test.js b/Sprint-3/3-mandatory-practice/implement/count.test.js index 943bbf027..16ab3ebd4 100644 --- a/Sprint-3/3-mandatory-practice/implement/count.test.js +++ b/Sprint-3/3-mandatory-practice/implement/count.test.js @@ -17,9 +17,20 @@ test("should count multiple occurrences of a character", () => { expect(count).toEqual(5); }); + + + // Scenario: No Occurrences // Given the input string str, // And a character char that does not exist within the case-sensitive str, // When the function is called with these inputs, // Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str. +test("should return 0 when character does not exist in string", () => { + const str = "Joseph"; + const char = "z"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); + +module.exports = countChar; \ No newline at end of file diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js index 2aa3e8e93..a5edab0dc 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js @@ -1,5 +1,16 @@ function getOrdinalNumber(num) { - return "1st"; + const j = num % 10; + const k = num % 100; + if (j === 1 && k !== 11) { + return num + "st"; + } + if (j === 2 && k !== 12) { + return num + "nd"; + } + if (j === 3 && k !== 13) { + return num + "rd"; + } + return num + "th"; } -module.exports = getOrdinalNumber; +module.exports = getOrdinalNumber; \ No newline at end of file diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js index 8a23ca998..4b6747e0a 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js @@ -11,4 +11,21 @@ const getOrdinalNumber = require("./get-ordinal-number"); test("should return '1st' for 1", () => { expect(getOrdinalNumber(1)).toEqual("1st"); }); - + +test("should return '2nd' for 2", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + }); + +test("should return '3rd' for 3", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); +}); + +test("should return '11th', '12th', and '13th' for teens", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); +}); + +test("should return '21st' for 21", () => { + expect(getOrdinalNumber(21)).toEqual("21st"); +}); \ No newline at end of file diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.js b/Sprint-3/3-mandatory-practice/implement/repeat.js index ae0379e1d..fa364d93f 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.js @@ -1,5 +1,11 @@ -function repeat() { - return "hellohellohello"; +function repeat(str, count) { + if (count < 0) throw new Error("Count must be non-negative"); + + let result = ""; + for (let i = 0; i < count; i++) { + result += str; + } + return result; } -module.exports = repeat; +module.exports = repeat; \ No newline at end of file diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.test.js b/Sprint-3/3-mandatory-practice/implement/repeat.test.js index 9da127be0..697de52e6 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.test.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.test.js @@ -21,13 +21,25 @@ test("should repeat the string count times", () => { // When the repeat function is called with these inputs, // Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition. +test("should return the original string when count is 1", () => { + expect(repeat("hello", 1)).toEqual("hello"); +}); + + // case: Handle Count of 0: // Given a target string str and a count equal to 0, // When the repeat function is called with these inputs, // Then it should return an empty string, ensuring that a count of 0 results in an empty output. +test("should return an empty string when count is 0", () => { + expect(repeat("hello", 0)).toEqual(""); +}); + // case: Negative Count: // Given a target string str and a negative integer count, // When the repeat function is called with these inputs, // Then it should throw an error or return an appropriate error message, as negative counts are not valid. +test("should throw an error when count is negative", () => { + expect(() => repeat("hello", -1)).toThrow("Count must be non-negative"); +}); \ No newline at end of file diff --git a/Sprint-3/4-stretch-investigate/find.js b/Sprint-3/4-stretch-investigate/find.js index dcc3e6bea..5c1018a24 100644 --- a/Sprint-3/4-stretch-investigate/find.js +++ b/Sprint-3/4-stretch-investigate/find.js @@ -10,9 +10,12 @@ function find(str, char) { 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 @@ -20,7 +23,17 @@ console.log(find("code your future", "z")); // Pay particular attention to the following: // a) How the index variable updates during the call to find +//// The index variable starts at 0 (the beginning of the string). After every unsuccessful check in the if statement, index++ adds 1 to the value. +// This allows the function to move sequentially from left to right through the string (0, 1, 2, 3...). + // b) What is the if statement used to check +//The if statement checks for equality. It looks at the character currently stored at str[index] and compares it to the char argument. +// If they are an exact match, the function stops immediately and returns the current position. + // c) Why is index++ being used? -// d) What is the condition index < str.length used for? + //This is the "iterator." Without index++, the loop would be stuck on index 0 forever because the condition index < str.length would always stay true. +// This would cause an infinite loop, likely crashing your browser or terminal. +// d) What is the condition index < str.length used for? +// This is the boundary condition. It ensures the loop only runs while there are still characters left to check. +// Once index reaches the length of the string, it means we have checked every character and should stop to avoid looking for "ghost" characters that don't exist. diff --git a/Sprint-3/4-stretch-investigate/password-validator.js b/Sprint-3/4-stretch-investigate/password-validator.js index 12dd1accf..08bd96323 100644 --- a/Sprint-3/4-stretch-investigate/password-validator.js +++ b/Sprint-3/4-stretch-investigate/password-validator.js @@ -2,5 +2,18 @@ function passwordValidator(password) { return password.length < 5 ? false : true } +function isValidPassword(password, previousPasswords = []) { + if (password.length < 5) return false; + if (!/[A-Z]/.test(password)) return false; + if (!/[a-z]/.test(password)) return false; + if (!/[0-9]/.test(password)) return false; + if (!/[^A-Za-z0-9]/.test(password)) return false; + if (previousPasswords.includes(password)) return false; + return true; +} -module.exports = passwordValidator; + + + + +module.exports = passwordValidator; \ No newline at end of file diff --git a/Sprint-3/4-stretch-investigate/password-validator.test.js b/Sprint-3/4-stretch-investigate/password-validator.test.js index 5909192b6..507a64661 100644 --- a/Sprint-3/4-stretch-investigate/password-validator.test.js +++ b/Sprint-3/4-stretch-investigate/password-validator.test.js @@ -14,13 +14,63 @@ To be valid, a password must: You must breakdown this problem in order to solve it. Find one test case first and get that working */ + const isValidPassword = require("./password-validator"); test("password has at least 5 characters", () => { - // Arrange const password = "12345"; - // Act const result = isValidPassword(password); - // Assert expect(result).toEqual(true); } ); + +test("password has at least one uppercase letter", () => { + const password = "abcD1!"; + const result = isValidPassword(password); + expect(result).toEqual(true); +} +); + +test("password has at least one lowercase letter", () => { + const password = "ABCd1!"; + const result = isValidPassword(password); + expect(result).toEqual(true); +} +); + +test("password has at least one number", () => { + const password = "Abcde!2"; + const result = isValidPassword(password); + expect(result).toEqual(true); +} +); + +test("password has at least one non-alphanumeric symbol", () => { + const password = "Abcde1"; + const result = isValidPassword(password); + expect(result).toEqual(true); +} +); + +test("password is not in the previous passwords array", () => { + const password = "Password1!"; + const previousPasswords = ["Password1!", "Password2@", "Password3#"]; + const result = isValidPassword(password, previousPasswords); + expect(result).toEqual(true); +} +); + +test("valid password meets all criteria", () => { + const password = "Valid1!"; + const previousPasswords = ["Password1!", "Password2@", "Password3#"]; + const result = isValidPassword(password, previousPasswords); + expect(result).toEqual(true); +} +); +test("invalid password fails multiple criteria", () => { + const password = "inv"; + const previousPasswords = ["inv", "Password2@", "Password3#"]; + const result = isValidPassword(password, previousPasswords); + expect(result).toEqual(false); +} +); +