From d249dd2be51cf8d969020f6e5bf6df59b3d787e3 Mon Sep 17 00:00:00 2001 From: Yonatan Teklemariam Date: Thu, 18 Jun 2026 16:37:46 +0100 Subject: [PATCH 1/4] debugged and corrected the errors accordingly. --- Sprint-1/1-key-exercises/1-count.js | 1 + Sprint-1/1-key-exercises/2-initials.js | 5 +-- Sprint-1/1-key-exercises/3-paths.js | 8 +++-- Sprint-1/1-key-exercises/4-random.js | 9 +++++ Sprint-1/2-mandatory-errors/0.js | 3 +- Sprint-1/2-mandatory-errors/1.js | 5 ++- Sprint-1/2-mandatory-errors/2.js | 2 +- Sprint-1/2-mandatory-errors/3.js | 10 +++++- Sprint-1/2-mandatory-errors/4.js | 4 +-- .../1-percentage-change.js | 18 +++++++++- .../3-mandatory-interpret/2-time-format.js | 9 +++++ Sprint-1/3-mandatory-interpret/3-to-pounds.js | 34 +++++++++++++++++++ Sprint-1/4-stretch-explore/chrome.md | 3 ++ Sprint-1/4-stretch-explore/objects.md | 9 +++++ 14 files changed, 108 insertions(+), 12 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6e..3e2a7f3876 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,4 @@ count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing +// line 3 is updating the value of the count variable by adding 1 to its current value. In other words, it is re-assignining the count variable to be equal to its previous value plus 1. It is called a statement. diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f6175..c0885c4c21 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,8 @@ 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]}`; -// https://www.google.com/search?q=get+first+character+of+string+mdn +console.log(initials); +// https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28e..29f13fddaf 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,9 @@ 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}`); +const ext = filePath.slice(filePath.lastIndexOf(".") + 1); +console.log(`The ext part of ${filePath} is ${ext}`); -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// https://www.google.com/search?q=slice+mdn diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aabb..dfdc3ad3e0 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -4,6 +4,15 @@ const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // In this exercise, you will need to work out what num represents? +// num represents a random integer between the minimum and maximum values, inclusive. The expression math.random() picks any decinmal number between 0 and 1, where then it's multiplied by the change of min & max + 1. Then the Math.floor() rounds the number down to the nearest integer and finally the minimum value is added to ensure the result is withn the specified range. + // Try breaking down the expression and using documentation to explain what it means +/* Math.random() generates a random decimal number between 0 (inclusive) and 1(not inclusive). +The expression (maximum - minimum +1) calculates the range of possible values, which is 100 - 1 + 1 = 100. +Then the result of Math.random() is multiplied by the range, which gives a random decimal number between 0 and 100 (not inclusive). +Math.floor() rounds the result down to the nearest integer, which gives a random integer between 0 and 99 (inclusive). +Finally, adding the minimum value of 1 shifts the range up by 1, resulting in a random integer between 1 and 100 (inclusive). */ + // 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 +console.log(num); diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f7..9c6cd4cc23 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,3 @@ 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? +// by adding a comment symbol in front of the lines, so that the computer ignores them when running the code. \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea76..1d8c3f1895 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,7 @@ // trying to create an age variable and then reassign the value by 1 const age = 33; -age = age + 1; +age = age + 1; // this line will cause an error because age is declared as constant and cannot be reassigned. + +let age = 33; +age += 1; // this line will work because age is declared as a variable and can be reassigned. diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831d..7bbfdbc782 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 ? - +// the error is that the variable cityOfBirth is being used before it is declared. console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884db..5d25e1a262 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,9 +1,17 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +const last4Digits = `${cardNumber.slice(-4)}`; // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working // Before running the code, make and explain a prediction about why the code won't work +// The code won't work because cardNumber is a number, and the slice method is a string method. So the cardNumber value needs to be coverted to a string. It can be done by using the cardNumber.toString() method or by using string(cardNumber) method or even by using template literals as shown in the code snippet. + // Then run the code and see what error it gives. +// The error says cardNumber.slice is not a function. This is becuase the slice method is a string method and cardNumber is a number. + // Consider: Why does it give this error? Is this what I predicted? If not, what's different? +// At first I thought the error would be that last4Digits is not defined, but I learned that the error is actually because the slice method is being called on a number, which doesn't have that method. // Then try updating the expression last4Digits is assigned to, in order to get the correct value +const last4Digits = cardNumber.toString().slice(-4); // first option +const last4Digits = String(cardNumber).slice(-4); // second option +const last4Digits = `${cardNumber}`.slice(-4); // third option diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 5f86c730bc..8b7ad0a76f 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,2 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +const 12HourClockTime = "8:53pm"; // this will throw an error because the variable name started with a number where it shouldn't be. +const 24hourClockTime = "20:53"; // the same happens here as well. diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e18..1e675d14e2 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,27 @@ 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 +/* There are 5 function calls in this code snippet. +1) carPrice = Number(carPrice.replaceAll(",", "")); --Number(...) & replaceAll(",", "") in this line +2) priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); --Number(...) & replaceAll("," "") in this line as well. +3) console.log(`The percentage change is ${percentageChange}`); +*/ // 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? +/* The error shown says ) missing after arguements in the expression of priceAfterOneYear. However when I looked into it carefully, the comma was missing between the arguments, not the ). I also used debugger in vscode and simply pointed out the problem by as on the debug console suggested. + */ // c) Identify all the lines that are variable reassignment statements +/* carPrice = Number(carPrice.replaceAll(",", "")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); +*/ // d) Identify all the lines that are variable declarations +/* let carPrice = "10,000"; +let priceAfterOneYear = "8,543"; +const priceDifference = carPrice - priceAfterOneYear; +const percentageChange = (priceDifference / carPrice) * 100; +*/ // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +// This expression is coverting the carPrice value by getting rid of the comma in the number and joining the number together. 10,000 ----> 10000 diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d2395587..30019e3ac3 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -12,14 +12,23 @@ 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? +// There are 6 declarations in this program. // b) How many function calls are there? +// 1 function call in the console.log(...); // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +/* movieLength % 60 represents the remaining seconds when the movie length of 8784 is divided by 60, thus giving the leftover seconds that don't fit into a full minute. +*/ // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +/* The expression subtracts the leftover seconds from the movie length and divides it by 60 to give the full minutes. Here's a simple formula to understand the logic, movie length = full minutes + leftover seconds +*/ // e) What do you think the variable result represents? Can you think of a better name for this variable? +/* The variable result outputs the time in a formatted time string of hours:minutes:seconds +It could be more clear to give it a better name like duration or movieDuration. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// I think it works for any positive number of seconds. \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69a..3705d0d73a 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -22,6 +22,40 @@ console.log(`£${pounds}.${pence}`); // You need to do a step-by-step breakdown of each line in this program // Try and describe the purpose / rationale behind each step +// line 1 is declaring a const variable and storing its value as 399p string where p is included in the amount text. +/* line 3 is is removing the trailing p from the string 399p. +//penceString.length for "399p" is 4. +penceString.length - 1 is 3. +substring(0, 3) takes characters at indexes 0, 1, and 2 ---> 399. + we removed p, so that we can add padding and splitting. +*/ +// line 8, we added padding to ensure the pence number is atleast 3 digits long by adding leading zeros if needed.Having at least 3 digits makes it easy to split into:pounds → all but the last 2 digit. pence → the last 2 digits +/* line 9 Extract the pounds part from the padded string. +paddedPenceNumberString.length is 3. + +length - 2 is 1. + +substring(0, 1) → takes index 0 only → "3". + +The last 2 digits represent pence. + +Everything before that represents pounds. +So we take from the start (0) up to (but not including) the position where the last 2 digits begin. +/* line 14 Extract the pence part and make sure it’s always 2 digits. + +length is 3. + +length - 2 is 1. + +substring(1) → takes from index 1 to the end → "99". + +Then padEnd(2, "0"): + +Ensures the pence string is always 2 characters long. + +For "99" → stays "99". + +Pence must always be shown as two digits (like £3.05, not £3.5). // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feafe..d726b86e84 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -11,8 +11,11 @@ In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? +// a pop up window appears with the message Hello World! 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? +// it has a function of prompting the user to input in the provided text box, along with the buttons ok and cancel. Where the user clicks ok without inputting anything in the text box, it returns " " in the console, but if the user clicks cancel, null is shown in the console. What is the return value of `prompt`? +// The return value of 'prompt' could be either null, " ", or user input (string). diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56a..8f0097d523 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -3,14 +3,23 @@ In this activity, we'll explore some additional concepts that you'll encounter in more depth later on in the course. Open the Chrome devtools Console, type in `console.log` and then hit enter +// I get 'console.log' What output do you get? Now enter just `console` in the Console, what output do you get back? +// output is 'console' Try also entering `typeof console` +// output is 'typeof console' Answer the following questions: What does `console` store? +// console stores functions inside it. + What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +// console.log -- logs the function in the console object. +// console.assert -- uses the assert function in the console object where it assert or checks whether something is true or false. If it is true, it does output nothing. But if it is false, it outputs an error message. +// "." -- is a property access operator. It gets something that belongs to its object. Example, console.log --> gets the log function inside the console +Math.round --> gets the round function inside Math From eb5ff4a47b93eb0b8254921aadff7e20c143c4e2 Mon Sep 17 00:00:00 2001 From: Yonatan Teklemariam Date: Mon, 22 Jun 2026 10:12:21 +0100 Subject: [PATCH 2/4] debugged and fixed buggy codes. --- Sprint-2/1-key-errors/0.js | 14 +++- Sprint-2/1-key-errors/1.js | 14 +++- Sprint-2/1-key-errors/2.js | 14 ++-- Sprint-2/2-mandatory-debug/0.js | 7 +- Sprint-2/2-mandatory-debug/1.js | 13 ++-- Sprint-2/2-mandatory-debug/2.js | 15 ++-- Sprint-2/3-mandatory-implement/1-bmi.js | 7 +- Sprint-2/3-mandatory-implement/2-cases.js | 4 ++ Sprint-2/3-mandatory-implement/3-to-pounds.js | 24 +++++++ Sprint-2/4-mandatory-interpret/time-format.js | 14 ++-- Sprint-2/5-stretch-extend/format-time.js | 70 +++++++++++++++++-- 11 files changed, 156 insertions(+), 40 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..3c1a528a3b 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,5 +1,6 @@ // Predict and explain first... -// =============> write your prediction here +// =============> I presume the str is repeatedly declared, first as a parameter and again as a variable. + // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring @@ -9,5 +10,12 @@ function capitalise(str) { return str; } -// =============> write your explanation here -// =============> write your new code here +// =============> str is already declared in the parameter and shouldn't be declared inside the function. The error says it's been declared already for this reason. Therefore we need to rename the str inside the function. +/* ==========> function capitalise(str) { +let result = `${str[0].toUpperCase()}${str.slice(1)}; +return result; +} +OR +function capitalise(str) { +return `${str[0].toUpperCase()}${str.slice(1)}`; +} diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..f58025aa25 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,7 +1,7 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> write your prediction here +// =============> The error will appear because we are trying to log the variable decimalNumber in the function. We have to call the function at this point. Besides to that, the decimalNumber is again declared inside the function where it shouldn't be. // Try playing computer with the example to work out what is going on @@ -14,7 +14,15 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); -// =============> write your explanation here +// =============> it says decimalNumber has aleady been declared for the above reason. // Finally, correct the code to fix the problem -// =============> write your new code here +/* ===========> function convertToPercentage(decimalNumber) { + let decimalNum = 0.5; + const percentage = `${decimalNum * 100}%`; + + return percentage; +} +const result = convertToPercentage(); +console.log(result); +*/ diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..41b005120f 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,20 +1,20 @@ - // 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 +// =============> It is going to throw an error message as 3 is written in incorrect position. That position is set only for parameters, not arguments. function square(3) { return num * num; } -// =============> write the error message here +// =============> in the node repl, it says unexpected number, as the function always expects a parameter to be declared in its definition. -// =============> explain this error message here +// =============> The error is already described above. // Finally, correct the code to fix the problem -// =============> write your new code here - - +/* ===========> function square(num) { +return num * num; +} +*/ diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..2e2ad2b7ef 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -8,7 +8,10 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// =============> write your explanation here +// =============> The function is only printing values on the console but not returning the value to the caller. Henceforth, it outputs both 320 and undefined on the console. 320 is the result of the console.log(a * b) inside the function, whereas undefined comes from the outer console.log(...) as it tries to bring forth and print the result of the function multiply(a, b). But the function is not returning any value and hence undefined appears on 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)}`); \ No newline at end of file diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcfd..0c2132b68b 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,16 @@ // Predict and explain first... -// =============> write your prediction here +// =============> As the function is not retuning anything, we're going to see undefined on the console. function sum(a, b) { - return; - a + b; + return a + b; } console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); -// =============> write your explanation here +// =============> The function uses parameters a and b. It calculates the addition of a and b. Supposedly it should return the result and then we can use the value of the function, but it is returning nothing at all as return is closed without being specified. // 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 ${(10, 32)}`); +*/ diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..54400a5a31 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,11 +1,11 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// =============> the function is going to return error as the /1 is not valid expression or syntax const num = 103; -function getLastDigit() { +function getLastDigit(num) { return num.toString().slice(-1); } @@ -14,11 +14,16 @@ 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 +/* ===========> function getLastDigit() { +return num.toString().slice(-1); + */ // Explain why the output is the way it is -// =============> write your explanation here +// =============> this is because the /1 is not defined and not valid in the system of javaScript languague, so it throws an error. Morever because the parameter for the function is not defined, the function takes the global variable scope to run the code inside it. So obviously, we need to put down a parameter which is num to have the function work for any number other than the global variable scope. // 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 index 17b1cbde1b..343ba7d3e8 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,8 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height -} \ No newline at end of file + const bmi = weight / (height * height); + return Math.round(bmi * 10) / 10; +} + +console.log(`The BMI of Yonatan is ${calculateBMI(65, 1.65)}`); diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad9..53b6da9c59 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,7 @@ // 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 snakeCaseString(str) { + return str.split(" ").join("_").toUpperCase(); +} +console.log(snakeCaseString("lord of the rings")); diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a703..c037bdce0e 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,27 @@ // You will need to declare a function called toPounds with an appropriately named parameter. // You should call this function a number of times to check it works for different inputs +const penceString = "399p"; + +function toPounds(penceString) { + const penceStringWithoutTrailingP = penceString.substring( + 0, + penceString.length - 1 + ); + + const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 + ); + + const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + return `£${pounds}.${pence}`; +} + +console.log(toPounds("39p")); +console.log(toPounds("100p")); +console.log(toPounds("4000p")); +console.log(toPounds("9p")); diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 17127bc01e..e75d3ee4ea 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -5,34 +5,36 @@ function pad(num) { } return numString; } +console.log(pad()); function formatTimeDisplay(seconds) { const remainingSeconds = seconds % 60; const totalMinutes = (seconds - remainingSeconds) / 60; const remainingMinutes = totalMinutes % 60; const totalHours = (totalMinutes - remainingMinutes) / 60; - return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } +console.log(formatTimeDisplay(61)); +// // You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit // to help you answer these questions // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> three times in terms of hours, minutes and seconds // 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 +// =============> the value assigned to num will be 1, and because the remaining seconds after 61 % 60 will be 1. // 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 +// =============> the return value of pad when it is called for the last time is "01". Because inside pad(), 1 is less than 2, and will be padded to "0" and will become "01". diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b8..9adf74eaed 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -10,16 +10,72 @@ function formatAs12HourClock(time) { return `${time} am`; } -const currentOutput = formatAs12HourClock("08:00"); -const targetOutput = "08:00 am"; +const currentOutput = formatAs12HourClock("00:00"); +const targetOutput = "12:00 am"; console.assert( currentOutput === targetOutput, - `current output: ${currentOutput}, target output: ${targetOutput}` + `current output: ${currentOutput}, target output: ${targetOutput}`, + "midnight should be 12:00 am" ); - -const currentOutput2 = formatAs12HourClock("23:00"); -const targetOutput2 = "11:00 pm"; +const currentOutput2 = formatAs12HourClock("00:30"); +const targetOutput2 = "12:30 am"; console.assert( currentOutput2 === targetOutput2, - `current output: ${currentOutput2}, target output: ${targetOutput2}` + `current output: ${currentOutput2}, target output: ${targetOutput2}`, + "00:30 should be 12:30 am" +); + +const currentOutput3 = formatAs12HourClock("01:30"); +const targetOutput3 = "01:30 am"; +console.assert( + currentOutput3 === targetOutput3, + `current output: ${currentOutput3}, target output: ${targetOutput3}`, + "01:30 should be 01:30 am" +); +const currentOutput4 = formatAs12HourClock("11:59"); +const targetOutput4 = "11:59 am"; +console.assert( + currentOutput4 === targetOutput4, + `current output: ${currentOutput4}, target output: ${targetOutput4}`, + "11:59 should be 11:59 am" +); +const currentOutput5 = formatAs12HourClock("12:30"); +const targetOutput5 = "12:30 pm"; +console.assert( + currentOutput5 === targetOutput5, + `current output: ${currentOutput5}, target output: ${targetOutput5}`, + "12:30 should be 12:30 pm" +); +const currentOutput6 = formatAs12HourClock("15:45"); +const targetOutput6 = "03:45 pm"; +console.assert( + currentOutput6 === targetOutput6, + `current output: ${currentOutput6}, target output: ${targetOutput6}`, + "15:45 should be 03:45 pm" +); +const currentOutput7 = formatAs12HourClock("23:30"); +const targetOutput7 = "11:30 pm"; +console.assert( + currentOutput7 === targetOutput7, + `current output: ${currentOutput7}, target output: ${targetOutput7}`, + "23:30 should be 11:30 pm" ); +// fixing the bugs found: +function formatAs12HourClock(time) { + const hours24 = Number(time.slice(0, 2)); // 23:00 ---> "23" + const minutes = time.slice(-2); // 23:00 ---> "00" + + let period = "am"; + let hours12 = hours24; + + if (hours24 === 0) { + hours12 = 12; // midnight + } else if (hours24 === 12) { + period = "pm"; // noon + } else if (hours24 > 12) { + hours12 = hours24 - 12; + period = "pm"; + } + + return `${String(hours12).padStart(2, "0")}:${minutes} ${period}`; // converts the return output to string type and padded to 2 length. +} From af905fcc210a118864dc720a1df1c84d2bb7c5ab Mon Sep 17 00:00:00 2001 From: Yonatan Teklemariam Date: Mon, 22 Jun 2026 10:40:35 +0100 Subject: [PATCH 3/4] added tests to extra check the function --- Sprint-2/1-key-errors/0.js | 3 +-- Sprint-2/1-key-errors/1.js | 1 - Sprint-2/2-mandatory-debug/2.js | 1 + 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 3c1a528a3b..aafe65f53b 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,7 +1,5 @@ // Predict and explain first... // =============> I presume the str is repeatedly declared, first as a parameter and again as a variable. - - // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring @@ -19,3 +17,4 @@ OR function capitalise(str) { return `${str[0].toUpperCase()}${str.slice(1)}`; } +*/ diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f58025aa25..8825e70ddb 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,5 +1,4 @@ // Predict and explain first... - // Why will an error occur when this program runs? // =============> The error will appear because we are trying to log the variable decimalNumber in the function. We have to call the function at this point. Besides to that, the decimalNumber is again declared inside the function where it shouldn't be. diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 54400a5a31..03f4180e89 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -12,6 +12,7 @@ function getLastDigit(num) { console.log(`The last digit of 42 is ${getLastDigit(42)}`); console.log(`The last digit of 105 is ${getLastDigit(105)}`); console.log(`The last digit of 806 is ${getLastDigit(806)}`); +console.log(`The last digit of 7247 is ${getLastDigit(7274)}`); // Now run the code and compare the output to your prediction /* ===========> function getLastDigit() { From 3d1f1b7850e2ac2daca073725323b1b585c5b8a2 Mon Sep 17 00:00:00 2001 From: Yonatan Teklemariam Date: Mon, 22 Jun 2026 10:53:44 +0100 Subject: [PATCH 4/4] Remove sprint 1 and 3 files from sprint 2 branch --- Sprint-1/1-key-exercises/1-count.js | 7 -- Sprint-1/1-key-exercises/2-initials.js | 12 --- Sprint-1/1-key-exercises/3-paths.js | 25 ----- Sprint-1/1-key-exercises/4-random.js | 18 ---- Sprint-1/2-mandatory-errors/0.js | 3 - Sprint-1/2-mandatory-errors/1.js | 7 -- Sprint-1/2-mandatory-errors/2.js | 5 - Sprint-1/2-mandatory-errors/3.js | 17 ---- Sprint-1/2-mandatory-errors/4.js | 2 - .../1-percentage-change.js | 38 -------- .../3-mandatory-interpret/2-time-format.js | 34 ------- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 61 ------------ Sprint-1/4-stretch-explore/chrome.md | 21 ----- Sprint-1/4-stretch-explore/objects.md | 25 ----- Sprint-1/readme.md | 35 ------- .../1-implement-and-rewrite-tests/README.md | 47 ---------- .../implement/1-get-angle-type.js | 37 -------- .../implement/2-is-proper-fraction.js | 33 ------- .../implement/3-get-card-value.js | 54 ----------- .../1-get-angle-type.test.js | 20 ---- .../2-is-proper-fraction.test.js | 10 -- .../3-get-card-value.test.js | 20 ---- .../testing-guide.md | 92 ------------------- Sprint-3/2-practice-tdd/README.md | 13 --- Sprint-3/2-practice-tdd/count.js | 5 - Sprint-3/2-practice-tdd/count.test.js | 24 ----- Sprint-3/2-practice-tdd/get-ordinal-number.js | 5 - .../2-practice-tdd/get-ordinal-number.test.js | 20 ---- Sprint-3/2-practice-tdd/repeat-str.js | 7 -- Sprint-3/2-practice-tdd/repeat-str.test.js | 32 ------- Sprint-3/3-dead-code/README.md | 9 -- Sprint-3/3-dead-code/exercise-1.js | 17 ---- Sprint-3/3-dead-code/exercise-2.js | 28 ------ Sprint-3/4-stretch/README.md | 9 -- Sprint-3/4-stretch/card-validator.md | 35 ------- Sprint-3/4-stretch/find.js | 25 ----- Sprint-3/4-stretch/password-validator.js | 6 -- Sprint-3/4-stretch/password-validator.test.js | 26 ------ Sprint-3/readme.md | 18 ---- 39 files changed, 902 deletions(-) delete mode 100644 Sprint-1/1-key-exercises/1-count.js delete mode 100644 Sprint-1/1-key-exercises/2-initials.js delete mode 100644 Sprint-1/1-key-exercises/3-paths.js delete mode 100644 Sprint-1/1-key-exercises/4-random.js delete mode 100644 Sprint-1/2-mandatory-errors/0.js delete mode 100644 Sprint-1/2-mandatory-errors/1.js delete mode 100644 Sprint-1/2-mandatory-errors/2.js delete mode 100644 Sprint-1/2-mandatory-errors/3.js delete mode 100644 Sprint-1/2-mandatory-errors/4.js delete mode 100644 Sprint-1/3-mandatory-interpret/1-percentage-change.js delete mode 100644 Sprint-1/3-mandatory-interpret/2-time-format.js delete mode 100644 Sprint-1/3-mandatory-interpret/3-to-pounds.js delete mode 100644 Sprint-1/4-stretch-explore/chrome.md delete mode 100644 Sprint-1/4-stretch-explore/objects.md delete mode 100644 Sprint-1/readme.md delete mode 100644 Sprint-3/1-implement-and-rewrite-tests/README.md delete mode 100644 Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js delete mode 100644 Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js delete mode 100644 Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js delete mode 100644 Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js delete mode 100644 Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js delete mode 100644 Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js delete mode 100644 Sprint-3/1-implement-and-rewrite-tests/testing-guide.md delete mode 100644 Sprint-3/2-practice-tdd/README.md delete mode 100644 Sprint-3/2-practice-tdd/count.js delete mode 100644 Sprint-3/2-practice-tdd/count.test.js delete mode 100644 Sprint-3/2-practice-tdd/get-ordinal-number.js delete mode 100644 Sprint-3/2-practice-tdd/get-ordinal-number.test.js delete mode 100644 Sprint-3/2-practice-tdd/repeat-str.js delete mode 100644 Sprint-3/2-practice-tdd/repeat-str.test.js delete mode 100644 Sprint-3/3-dead-code/README.md delete mode 100644 Sprint-3/3-dead-code/exercise-1.js delete mode 100644 Sprint-3/3-dead-code/exercise-2.js delete mode 100644 Sprint-3/4-stretch/README.md delete mode 100644 Sprint-3/4-stretch/card-validator.md delete mode 100644 Sprint-3/4-stretch/find.js delete mode 100644 Sprint-3/4-stretch/password-validator.js delete mode 100644 Sprint-3/4-stretch/password-validator.test.js delete mode 100644 Sprint-3/readme.md diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js deleted file mode 100644 index 3e2a7f3876..0000000000 --- a/Sprint-1/1-key-exercises/1-count.js +++ /dev/null @@ -1,7 +0,0 @@ -let count = 0; - -count = count + 1; - -// Line 1 is a variable declaration, creating the count variable with an initial value of 0 -// Describe what line 3 is doing, in particular focus on what = is doing -// line 3 is updating the value of the count variable by adding 1 to its current value. In other words, it is re-assignining the count variable to be equal to its previous value plus 1. It is called a statement. diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js deleted file mode 100644 index c0885c4c21..0000000000 --- a/Sprint-1/1-key-exercises/2-initials.js +++ /dev/null @@ -1,12 +0,0 @@ -let firstName = "Creola"; -let middleName = "Katherine"; -let lastName = "Johnson"; - -// Declare a variable called initials that stores the first character of each string. -// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. - -let initials = `${firstName[0]}${middleName[0]}${lastName[0]}`; - -console.log(initials); - -// https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js deleted file mode 100644 index 29f13fddaf..0000000000 --- a/Sprint-1/1-key-exercises/3-paths.js +++ /dev/null @@ -1,25 +0,0 @@ -// The diagram below shows the different names for parts of a file path on a Unix operating system - -// ┌─────────────────────┬────────────┐ -// │ dir │ base │ -// ├──────┬ ├──────┬─────┤ -// │ root │ │ name │ ext │ -// " / home/user/dir / file .txt " -// └──────┴──────────────┴──────┴─────┘ - -// (All spaces in the "" line should be ignored. They are purely for formatting.) - -const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; -const lastSlashIndex = filePath.lastIndexOf("/"); -const base = filePath.slice(lastSlashIndex + 1); -console.log(`The base part of ${filePath} is ${base}`); - -// Create a variable to store the dir part of the filePath variable -// Create a variable to store the ext part of the variable - -const dir = filePath.slice(0, lastSlashIndex); -console.log(`The dir part of ${filePath} is ${dir}`); -const ext = filePath.slice(filePath.lastIndexOf(".") + 1); -console.log(`The ext part of ${filePath} is ${ext}`); - -// https://www.google.com/search?q=slice+mdn diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js deleted file mode 100644 index dfdc3ad3e0..0000000000 --- a/Sprint-1/1-key-exercises/4-random.js +++ /dev/null @@ -1,18 +0,0 @@ -const minimum = 1; -const maximum = 100; - -const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; - -// In this exercise, you will need to work out what num represents? -// num represents a random integer between the minimum and maximum values, inclusive. The expression math.random() picks any decinmal number between 0 and 1, where then it's multiplied by the change of min & max + 1. Then the Math.floor() rounds the number down to the nearest integer and finally the minimum value is added to ensure the result is withn the specified range. - -// Try breaking down the expression and using documentation to explain what it means -/* Math.random() generates a random decimal number between 0 (inclusive) and 1(not inclusive). -The expression (maximum - minimum +1) calculates the range of possible values, which is 100 - 1 + 1 = 100. -Then the result of Math.random() is multiplied by the range, which gives a random decimal number between 0 and 100 (not inclusive). -Math.floor() rounds the result down to the nearest integer, which gives a random integer between 0 and 99 (inclusive). -Finally, adding the minimum value of 1 shifts the range up by 1, resulting in a random integer between 1 and 100 (inclusive). */ - -// 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 -console.log(num); diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js deleted file mode 100644 index 9c6cd4cc23..0000000000 --- a/Sprint-1/2-mandatory-errors/0.js +++ /dev/null @@ -1,3 +0,0 @@ -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? -// by adding a comment symbol in front of the lines, so that the computer ignores them when running the code. \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js deleted file mode 100644 index 1d8c3f1895..0000000000 --- a/Sprint-1/2-mandatory-errors/1.js +++ /dev/null @@ -1,7 +0,0 @@ -// trying to create an age variable and then reassign the value by 1 - -const age = 33; -age = age + 1; // this line will cause an error because age is declared as constant and cannot be reassigned. - -let age = 33; -age += 1; // this line will work because age is declared as a variable and can be reassigned. diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js deleted file mode 100644 index 7bbfdbc782..0000000000 --- a/Sprint-1/2-mandatory-errors/2.js +++ /dev/null @@ -1,5 +0,0 @@ -// Currently trying to print the string "I was born in Bolton" but it isn't working... -// what's the error ? -// the error is that the variable cityOfBirth is being used before it is declared. -console.log(`I was born in ${cityOfBirth}`); -const cityOfBirth = "Bolton"; diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js deleted file mode 100644 index 5d25e1a262..0000000000 --- a/Sprint-1/2-mandatory-errors/3.js +++ /dev/null @@ -1,17 +0,0 @@ -const cardNumber = 4533787178994213; -const last4Digits = `${cardNumber.slice(-4)}`; - -// The last4Digits variable should store the last 4 digits of cardNumber -// However, the code isn't working -// Before running the code, make and explain a prediction about why the code won't work -// The code won't work because cardNumber is a number, and the slice method is a string method. So the cardNumber value needs to be coverted to a string. It can be done by using the cardNumber.toString() method or by using string(cardNumber) method or even by using template literals as shown in the code snippet. - -// Then run the code and see what error it gives. -// The error says cardNumber.slice is not a function. This is becuase the slice method is a string method and cardNumber is a number. - -// Consider: Why does it give this error? Is this what I predicted? If not, what's different? -// At first I thought the error would be that last4Digits is not defined, but I learned that the error is actually because the slice method is being called on a number, which doesn't have that method. -// Then try updating the expression last4Digits is assigned to, in order to get the correct value -const last4Digits = cardNumber.toString().slice(-4); // first option -const last4Digits = String(cardNumber).slice(-4); // second option -const last4Digits = `${cardNumber}`.slice(-4); // third option diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js deleted file mode 100644 index 8b7ad0a76f..0000000000 --- a/Sprint-1/2-mandatory-errors/4.js +++ /dev/null @@ -1,2 +0,0 @@ -const 12HourClockTime = "8:53pm"; // this will throw an error because the variable name started with a number where it shouldn't be. -const 24hourClockTime = "20:53"; // the same happens here as well. diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js deleted file mode 100644 index 1e675d14e2..0000000000 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ /dev/null @@ -1,38 +0,0 @@ -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 -/* There are 5 function calls in this code snippet. -1) carPrice = Number(carPrice.replaceAll(",", "")); --Number(...) & replaceAll(",", "") in this line -2) priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); --Number(...) & replaceAll("," "") in this line as well. -3) console.log(`The percentage change is ${percentageChange}`); -*/ - -// 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? -/* The error shown says ) missing after arguements in the expression of priceAfterOneYear. However when I looked into it carefully, the comma was missing between the arguments, not the ). I also used debugger in vscode and simply pointed out the problem by as on the debug console suggested. - */ - -// c) Identify all the lines that are variable reassignment statements -/* carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); -*/ - -// d) Identify all the lines that are variable declarations -/* let carPrice = "10,000"; -let priceAfterOneYear = "8,543"; -const priceDifference = carPrice - priceAfterOneYear; -const percentageChange = (priceDifference / carPrice) * 100; -*/ - -// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? -// This expression is coverting the carPrice value by getting rid of the comma in the number and joining the number together. 10,000 ----> 10000 diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js deleted file mode 100644 index 30019e3ac3..0000000000 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ /dev/null @@ -1,34 +0,0 @@ -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? -// There are 6 declarations in this program. - -// b) How many function calls are there? -// 1 function call in the console.log(...); - -// c) Using documentation, explain what the expression movieLength % 60 represents -// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators -/* movieLength % 60 represents the remaining seconds when the movie length of 8784 is divided by 60, thus giving the leftover seconds that don't fit into a full minute. -*/ - -// d) Interpret line 4, what does the expression assigned to totalMinutes mean? -/* The expression subtracts the leftover seconds from the movie length and divides it by 60 to give the full minutes. Here's a simple formula to understand the logic, movie length = full minutes + leftover seconds -*/ - -// e) What do you think the variable result represents? Can you think of a better name for this variable? -/* The variable result outputs the time in a formatted time string of hours:minutes:seconds -It could be more clear to give it a better name like duration or movieDuration. - -// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer -// I think it works for any positive number of seconds. \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js deleted file mode 100644 index 3705d0d73a..0000000000 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ /dev/null @@ -1,61 +0,0 @@ -const penceString = "399p"; - -const penceStringWithoutTrailingP = penceString.substring( - 0, - penceString.length - 1 -); - -const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); -const pounds = paddedPenceNumberString.substring( - 0, - paddedPenceNumberString.length - 2 -); - -const pence = paddedPenceNumberString - .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); - -console.log(`£${pounds}.${pence}`); - -// This program takes a string representing a price in pence -// The program then builds up a string representing the price in pounds - -// You need to do a step-by-step breakdown of each line in this program -// Try and describe the purpose / rationale behind each step -// line 1 is declaring a const variable and storing its value as 399p string where p is included in the amount text. -/* line 3 is is removing the trailing p from the string 399p. -//penceString.length for "399p" is 4. -penceString.length - 1 is 3. -substring(0, 3) takes characters at indexes 0, 1, and 2 ---> 399. - we removed p, so that we can add padding and splitting. -*/ -// line 8, we added padding to ensure the pence number is atleast 3 digits long by adding leading zeros if needed.Having at least 3 digits makes it easy to split into:pounds → all but the last 2 digit. pence → the last 2 digits -/* line 9 Extract the pounds part from the padded string. - -paddedPenceNumberString.length is 3. - -length - 2 is 1. - -substring(0, 1) → takes index 0 only → "3". - -The last 2 digits represent pence. - -Everything before that represents pounds. -So we take from the start (0) up to (but not including) the position where the last 2 digits begin. -/* line 14 Extract the pence part and make sure it’s always 2 digits. - -length is 3. - -length - 2 is 1. - -substring(1) → takes from index 1 to the end → "99". - -Then padEnd(2, "0"): - -Ensures the pence string is always 2 characters long. - -For "99" → stays "99". - -Pence must always be shown as two digits (like £3.05, not £3.5). -// To begin, we can start with -// 1. const penceString = "399p": initialises a string variable with the value "399p" diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md deleted file mode 100644 index d726b86e84..0000000000 --- a/Sprint-1/4-stretch-explore/chrome.md +++ /dev/null @@ -1,21 +0,0 @@ -Open a new window in Chrome, - -then locate the **Console** tab. - -Voila! You now have access to the [Chrome V8 Engine](https://www.cloudflare.com/en-gb/learning/serverless/glossary/what-is-chrome-v8/). -Just like the Node REPL, you can input JavaScript code into the Console tab and the V8 engine will execute it. - -Let's try an example. - -In the Chrome console, -invoke the function `alert` with an input string of `"Hello world!"`; - -What effect does calling the `alert` function have? -// a pop up window appears with the message Hello World! - -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? -// it has a function of prompting the user to input in the provided text box, along with the buttons ok and cancel. Where the user clicks ok without inputting anything in the text box, it returns " " in the console, but if the user clicks cancel, null is shown in the console. -What is the return value of `prompt`? -// The return value of 'prompt' could be either null, " ", or user input (string). diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md deleted file mode 100644 index 8f0097d523..0000000000 --- a/Sprint-1/4-stretch-explore/objects.md +++ /dev/null @@ -1,25 +0,0 @@ -## Objects - -In this activity, we'll explore some additional concepts that you'll encounter in more depth later on in the course. - -Open the Chrome devtools Console, type in `console.log` and then hit enter -// I get 'console.log' - -What output do you get? - -Now enter just `console` in the Console, what output do you get back? -// output is 'console' - -Try also entering `typeof console` -// output is 'typeof console' - -Answer the following questions: - -What does `console` store? -// console stores functions inside it. - -What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? -// console.log -- logs the function in the console object. -// console.assert -- uses the assert function in the console object where it assert or checks whether something is true or false. If it is true, it does output nothing. But if it is false, it outputs an error message. -// "." -- is a property access operator. It gets something that belongs to its object. Example, console.log --> gets the log function inside the console -Math.round --> gets the round function inside Math diff --git a/Sprint-1/readme.md b/Sprint-1/readme.md deleted file mode 100644 index 62d24c9580..0000000000 --- a/Sprint-1/readme.md +++ /dev/null @@ -1,35 +0,0 @@ -# 🧭 Guide to Week 1 exercises - -> https://programming.codeyourfuture.io/structuring-data/sprints/1/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 README will guide you through the different sections for this week. - -## 1 Exercises - -In this section, you'll have a short program and task. Some of the syntax may be unfamiliar - in this case, you'll need to look things up in documentation. - -https://developer.mozilla.org/en-US/docs/Web/JavaScript - -## 2 Errors - -In this section, you'll need to go to each file in `errors` directory and 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. - -## 3 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. - -https://developer.mozilla.org/en-US/docs/Web/JavaScript - -## 4 Explore - Stretch 💪 - -This stretch activity will get you to start exploring new concepts and environments by yourself. It will do so by prompting you to reflect on some questions. 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 9e05a871e2..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ /dev/null @@ -1,37 +0,0 @@ -// Implement a function getAngleType -// -// When given an angle in degrees, it should return a string indicating the type of angle: -// - "Acute angle" for angles greater than 0° and less than 90° -// - "Right angle" for exactly 90° -// - "Obtuse angle" for angles greater than 90° and less than 180° -// - "Straight angle" for exactly 180° -// - "Reflex angle" for angles greater than 180° and less than 360° -// - "Invalid angle" for angles outside the valid range. - -// Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.) - -// Acceptance criteria: -// After you have implemented the function, write tests to cover all the cases, and -// execute the code to ensure all tests pass. - -function getAngleType(angle) { - // TODO: Implement this function -} - -// 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 970cb9b641..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ /dev/null @@ -1,33 +0,0 @@ -// Implement a function isProperFraction, -// when given two numbers, a numerator and a denominator, it should return true if -// the given numbers form a proper fraction, and false otherwise. - -// Assumption: The parameters are valid numbers (not NaN or Infinity). - -// Note: If you are unfamiliar with proper fractions, please look up its mathematical definition. - -// Acceptance criteria: -// After you have implemented the function, write tests to cover all the cases, and -// execute the code to ensure all tests pass. - -function isProperFraction(numerator, denominator) { - // TODO: Implement this function -} - -// 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 ff5c532e1d..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ /dev/null @@ -1,54 +0,0 @@ -// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck - -// Implement a function getCardValue, when given a string representing a playing card, -// should return the numerical value of the card. - -// A valid card string will contain a rank followed by the suit. -// The rank can be one of the following strings: -// "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" -// The suit can be one of the following emojis: -// "♠", "♥", "♦", "♣" -// For example: "A♠", "2♥", "10♥", "J♣", "Q♦", "K♦". - -// When the card is an ace ("A"), the function should return 11. -// When the card is a face card ("J", "Q", "K"), the function should return 10. -// When the card is a number card ("2" to "10"), the function should return its numeric value. - -// When the card string is invalid (not following the above format), the function should -// throw an error. - -// Acceptance criteria: -// After you have implemented the function, write tests to cover all the cases, and -// execute the code to ensure all tests pass. - -function getCardValue(card) { - // TODO: Implement this function -} - -// 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 d777f348d3..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js +++ /dev/null @@ -1,20 +0,0 @@ -// This statement loads the getAngleType function you wrote in the implement directory. -// We will use the same function, but write tests for it using Jest in this file. -const getAngleType = require("../implement/1-get-angle-type"); - -// TODO: Write tests in Jest syntax to cover all cases/outcomes, -// including boundary and invalid cases. - -// Case 1: Acute angles -test(`should return "Acute angle" when (0 < angle < 90)`, () => { - // Test various acute angles, including boundary cases - expect(getAngleType(1)).toEqual("Acute angle"); - expect(getAngleType(45)).toEqual("Acute angle"); - expect(getAngleType(89)).toEqual("Acute angle"); -}); - -// Case 2: Right angle -// Case 3: Obtuse angles -// Case 4: Straight angle -// Case 5: Reflex angles -// Case 6: Invalid angles diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js deleted file mode 100644 index 7f087b2ba1..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ /dev/null @@ -1,10 +0,0 @@ -// This statement loads the isProperFraction function you wrote in the implement directory. -// We will use the same function, but write tests for it using Jest in this file. -const isProperFraction = require("../implement/2-is-proper-fraction"); - -// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories. - -// Special case: numerator is zero -test(`should return false when denominator is zero`, () => { - expect(isProperFraction(1, 0)).toEqual(false); -}); diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js deleted file mode 100644 index cf7f9dae2e..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ /dev/null @@ -1,20 +0,0 @@ -// This statement loads the getCardValue function you wrote in the implement directory. -// We will use the same function, but write tests for it using Jest in this file. -const getCardValue = require("../implement/3-get-card-value"); - -// TODO: Write tests in Jest syntax to cover all possible outcomes. - -// Case 1: Ace (A) -test(`Should return 11 when given an ace card`, () => { - expect(getCardValue("A♠")).toEqual(11); -}); - -// Suggestion: Group the remaining test data into these categories: -// Number Cards (2-10) -// Face Cards (J, Q, K) -// Invalid Cards - -// To learn how to test whether a function throws an error as expected in Jest, -// please refer to the Jest documentation: -// https://jestjs.io/docs/expect#tothrowerror - diff --git a/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md b/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md deleted file mode 100644 index 917194e7a9..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md +++ /dev/null @@ -1,92 +0,0 @@ -# A Beginner's Guide to Testing Functions - -## 1. What Is a Function? - -``` -Input ──▶ Function ──▶ Output -``` - -A function -- Takes **input** (via **arguments**) -- Does some work -- Produces **one output** (via a **return value**) - -Example: - -``` -sum(2, 3) → 5 -``` - -Important idea: the same input should produce the same output. - - -## 2. Testing Means Predicting - -Testing means: -> If I give this input, what output should I get? - - -## 3. Choosing Good Test Values - -### Step 1: Determining the space of possible inputs -Ask: -- What type of value is expected? -- What values make sense? - - If they are numbers: - - Are they integers or floating-point numbers? - - What is their range? - - If they are strings: - - What are their length and patterns? -- What values would not make sense? - -### Step 2: Choosing Good Test Values - -#### Normal Cases - -These confirm that the function works in normal use. - -- What does a typical, ordinary input look like? -- Are there multiple ordinary groups of inputs? e.g. for an age checking function, maybe there are "adults" and "children" as expected ordinary groups of inputs. - - -#### Boundary Cases - -Test values exactly at, just inside, and just outside defined ranges. -These values are where logic breaks most often. - -#### Consider All Outcomes - -Every outcome must be reached by at least one test. - -- How many different results can this function produce? -- Have I tested a value that leads to each one? - -#### Crossing the Edges and Invalid Values - -This tests how the function behaves when assumptions are violated. -- What happens when input is outside of the expected range? -- What happens when input is not of the expected type? -- What happens when input is not in the expected format? - -## 4. How to Test - -### 1. Using `console.assert()` - -```javascript - // Report a failure only when the first argument is false - console.assert( sum(4, 6) === 10, "Expected 4 + 6 to equal 10" ); -``` - -It is simpler than using `if-else` and requires no setup. - -### 2. Jest Testing Framework - -```javascript - test("Should correctly return the sum of two positive numbers", () => { - expect( sum(4, 6) ).toEqual(10); - ... // Can test multiple samples - }); - -``` - -Jest supports many useful functions for testing but requires additional setup. diff --git a/Sprint-3/2-practice-tdd/README.md b/Sprint-3/2-practice-tdd/README.md deleted file mode 100644 index f7d82fe43d..0000000000 --- a/Sprint-3/2-practice-tdd/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Practice TDD - -In this section you'll practice this key skill of building up your program test first. - -Use the Jest syntax and complete the provided files, meeting the acceptance criteria for each function. Use the VSCode test runner to run your tests and check your progress. - -Write the tests _before_ the code that will make them pass. - -Recommended order: - -1. `count.test.js` -1. `repeat-str.test.js` -1. `get-ordinal-number.test.js` diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js deleted file mode 100644 index 95b6ebb7d4..0000000000 --- a/Sprint-3/2-practice-tdd/count.js +++ /dev/null @@ -1,5 +0,0 @@ -function countChar(stringOfCharacters, findCharacter) { - return 5 -} - -module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js deleted file mode 100644 index 179ea0ddf7..0000000000 --- a/Sprint-3/2-practice-tdd/count.test.js +++ /dev/null @@ -1,24 +0,0 @@ -// implement a function countChar that counts the number of times a character occurs in a string -const countChar = require("./count"); -// Given a string `str` and a single character `char` to search for, -// When the countChar function is called with these inputs, -// Then it should: - -// Scenario: Multiple Occurrences -// Given the input string `str`, -// And a character `char` that occurs one or more times in `str` (e.g., 'a' in 'aaaaa'), -// When the function is called with these inputs, -// Then it should correctly count occurrences of `char`. - -test("should count multiple occurrences of a character", () => { - const str = "aaaaa"; - const char = "a"; - const count = countChar(str, char); - expect(count).toEqual(5); -}); - -// Scenario: No Occurrences -// Given the input string `str`, -// And a character `char` that does not exist within `str`. -// When the function is called with these inputs, -// Then it should return 0, indicating that no occurrences of `char` were found. diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js deleted file mode 100644 index f95d71db13..0000000000 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ /dev/null @@ -1,5 +0,0 @@ -function getOrdinalNumber(num) { - return "1st"; -} - -module.exports = getOrdinalNumber; diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js deleted file mode 100644 index adfa58560f..0000000000 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ /dev/null @@ -1,20 +0,0 @@ -const getOrdinalNumber = require("./get-ordinal-number"); -// In this week's prep, we started implementing getOrdinalNumber. - -// Continue testing and implementing getOrdinalNumber for additional cases. -// Write your tests using Jest — remember to run your tests often for continual feedback. - -// To ensure thorough testing, we need broad scenarios that cover all possible cases. -// Listing individual values, however, can quickly lead to an unmanageable number of test cases. -// Instead of writing tests for individual numbers, consider grouping all possible input values -// into meaningful categories. Then, select representative samples from each category to test. -// This approach improves coverage and makes our tests easier to maintain. - -// Case 1: Numbers ending with 1 (but not 11) -// When the number ends with 1, except those ending with 11, -// Then the function should return a string by appending "st" to the number. -test("should append 'st' for numbers ending with 1, except those ending with 11", () => { - expect(getOrdinalNumber(1)).toEqual("1st"); - expect(getOrdinalNumber(21)).toEqual("21st"); - expect(getOrdinalNumber(131)).toEqual("131st"); -}); diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js deleted file mode 100644 index 2af0a2cea7..0000000000 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ /dev/null @@ -1,7 +0,0 @@ -function repeatStr() { - // Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat). - // The goal is to re-implement that function, not to use it. - return "hellohellohello"; -} - -module.exports = repeatStr; diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js deleted file mode 100644 index a3fc1196c4..0000000000 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ /dev/null @@ -1,32 +0,0 @@ -// Implement a function repeatStr -const repeatStr = require("./repeat-str"); -// Given a target string `str` and a positive integer `count`, -// When the repeatStr function is called with these inputs, -// Then it should: - -// Case: handle multiple repetitions: -// Given a target string `str` and a positive integer `count` greater than 1, -// When the repeatStr function is called with these inputs, -// Then it should return a string that contains the original `str` repeated `count` times. - -test("should repeat the string count times", () => { - const str = "hello"; - const count = 3; - const repeatedStr = repeatStr(str, count); - expect(repeatedStr).toEqual("hellohellohello"); -}); - -// Case: handle count of 1: -// Given a target string `str` and a `count` equal to 1, -// When the repeatStr function is called with these inputs, -// Then it should return the original `str` without repetition. - -// Case: Handle count of 0: -// Given a target string `str` and a `count` equal to 0, -// When the repeatStr function is called with these inputs, -// Then it should return an empty string. - -// Case: Handle negative count: -// Given a target string `str` and a negative integer `count`, -// When the repeatStr function is called with these inputs, -// Then it should throw an error, as negative counts are not valid. diff --git a/Sprint-3/3-dead-code/README.md b/Sprint-3/3-dead-code/README.md deleted file mode 100644 index 2bfbfff819..0000000000 --- a/Sprint-3/3-dead-code/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Refactoring Dead Code - -Here are two example of code that has not been built efficiently. Both files have dead code in them. It's your job to go back through this existing code, identify the dead code, and remove it so the code is ready for production. - -## Instructions - -1. Work through each `exercise` file inside this directory. -2. Delete the dead code. -3. Commit your changes and make a PR when done. diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js deleted file mode 100644 index 4d09f15fa9..0000000000 --- a/Sprint-3/3-dead-code/exercise-1.js +++ /dev/null @@ -1,17 +0,0 @@ -// Find the instances of unreachable and redundant code - remove them! -// The sayHello function should continue to work for any reasonable input it's given. - -let testName = "Jerry"; -const greeting = "hello"; - -function sayHello(greeting, name) { - const greetingStr = greeting + ", " + name + "!"; - return `${greeting}, ${name}!`; - console.log(greetingStr); -} - -testName = "Aman"; - -const greetingMessage = sayHello(greeting, testName); - -console.log(greetingMessage); // 'hello, Aman!' diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js deleted file mode 100644 index 56d7887c4c..0000000000 --- a/Sprint-3/3-dead-code/exercise-2.js +++ /dev/null @@ -1,28 +0,0 @@ -// Remove the unused code that does not contribute to the final console log -// The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable. - -const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; -const capitalisedPets = pets.map((pet) => pet.toUpperCase()); -const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); - -function logPets(petsArr) { - petsArr.forEach((pet) => console.log(pet)); -} - -function countAndCapitalisePets(petsArr) { - const petCount = {}; - - petsArr.forEach((pet) => { - const capitalisedPet = pet.toUpperCase(); - if (petCount[capitalisedPet]) { - petCount[capitalisedPet] += 1; - } else { - petCount[capitalisedPet] = 1; - } - }); - return petCount; -} - -const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH); - -console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log diff --git a/Sprint-3/4-stretch/README.md b/Sprint-3/4-stretch/README.md deleted file mode 100644 index 8f01227bf9..0000000000 --- a/Sprint-3/4-stretch/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# 🔍 Stretch - -These stretch activities are not mandatory, but we hope you will explore them after you have completed the mandatory work. - -In this exercise, you'll need to **play computer** with the function `find`. This function makes use of while loop statement. Your task will be to step through the code to figure out what is happening when the computer executes the code. - -Next, try implementing the functions specified in `password-validator.js`. - -Finally, set up your own script and test files for `card-validator.md` diff --git a/Sprint-3/4-stretch/card-validator.md b/Sprint-3/4-stretch/card-validator.md deleted file mode 100644 index e39c6ace6e..0000000000 --- a/Sprint-3/4-stretch/card-validator.md +++ /dev/null @@ -1,35 +0,0 @@ -## **PROJECT: Credit Card Validator** - -In this project you'll write a script that validates whether or not a credit card number is valid. - -Here are the rules for a valid number: - -- Number must be 16 digits, all of them must be numbers. -- You must have at least two different digits represented (all of the digits cannot be the same). -- The final digit must be even. -- The sum of all the digits must be greater than 16. - -For example, the following credit card numbers are valid: - -```markdown -9999777788880000 -6666666666661666 -``` - -And the following credit card numbers are invalid: - -```markdown -a92332119c011112 (invalid characters) -4444444444444444 (only one type of number) -1111111111111110 (sum less than 16) -6666666666666661 (odd final number) -``` - -These are the requirements your project needs to fulfill: - -- Make a JavaScript file with a name that describes its contents. -- Create a function with a descriptive name which makes it clear what the function does. The function should take one argument, the credit card number to validate. -- Write at least 2 comments that explain to others what a line of code is meant to do. -- Return a boolean from the function to indicate whether the credit card number is valid. - -Good luck! diff --git a/Sprint-3/4-stretch/find.js b/Sprint-3/4-stretch/find.js deleted file mode 100644 index c7e79a2f21..0000000000 --- a/Sprint-3/4-stretch/find.js +++ /dev/null @@ -1,25 +0,0 @@ -function find(str, char) { - let index = 0; - - while (index < str.length) { - if (str[index] === char) { - return index; - } - index++; - } - return -1; -} - -console.log(find("code your future", "u")); -console.log(find("code your future", "z")); - -// The while loop statement allows us to do iteration - the repetition of a certain number of tasks according to some condition -// See the docs https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while - -// Use the Python Visualiser to help you play computer with this example and observe how this code is executed -// Pay particular attention to the following: - -// a) How the index variable updates during the call to find -// b) What is the if statement used to check -// c) Why is index++ being used? -// d) What is the condition index < str.length used for? diff --git a/Sprint-3/4-stretch/password-validator.js b/Sprint-3/4-stretch/password-validator.js deleted file mode 100644 index b55d527dba..0000000000 --- a/Sprint-3/4-stretch/password-validator.js +++ /dev/null @@ -1,6 +0,0 @@ -function passwordValidator(password) { - return password.length < 5 ? false : true -} - - -module.exports = passwordValidator; \ No newline at end of file diff --git a/Sprint-3/4-stretch/password-validator.test.js b/Sprint-3/4-stretch/password-validator.test.js deleted file mode 100644 index 8fa3089d6b..0000000000 --- a/Sprint-3/4-stretch/password-validator.test.js +++ /dev/null @@ -1,26 +0,0 @@ -/* -Password Validation - -Write a program that should check if a password is valid -and returns a boolean - -To be valid, a password must: -- Have at least 5 characters. -- Have at least one English uppercase letter (A-Z) -- Have at least one English lowercase letter (a-z) -- Have at least one number (0-9) -- Have at least one of the following non-alphanumeric symbols: ("!", "#", "$", "%", ".", "*", "&") -- Must not be any previous password in the passwords array. - -You must breakdown this problem in order to solve it. Find one test case first and get that working -*/ -const isValidPassword = require("./password-validator"); -test("password has at least 5 characters", () => { - // Arrange - const password = "12345"; - // Act - const result = isValidPassword(password); - // Assert - expect(result).toEqual(true); -} -); \ No newline at end of file diff --git a/Sprint-3/readme.md b/Sprint-3/readme.md deleted file mode 100644 index 028950b927..0000000000 --- a/Sprint-3/readme.md +++ /dev/null @@ -1,18 +0,0 @@ -# 🧭 Guide to week 3 exercises - -> https://programming.codeyourfuture.io/structuring-data/sprints/3/prep/ - -> [!TIP] -> You should always do the prep work _before_ attempting the coursework. -> The prep shows you how to do the coursework. -> There is often a step by step video you can code along with too. -> Do the prep. - -This sprint you are expected to produce multiple different pull requests: - -1. One pull request for the `1-implement-and-rewrite-tests` directory. -2. One pull request for the `2-practice-tdd` directory. -3. One pull request for the `3-dead-code` directory. -4. Optionally, one pull request for the `4-stretch` directory. - -Each directory contains a README.md file with instructions for that directory.