From cd53cebe4a40ec6a817d2bf11adec4c226dda533 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Sat, 19 Sep 2026 23:40:41 +0100 Subject: [PATCH 01/13] Committing prep, don't correct this --- prep/parameters.js | 5 +++++ prep/passwordCheckerFunction.js | 10 ++++++++++ prep/using-a-function.js | 4 ++++ 3 files changed, 19 insertions(+) create mode 100644 prep/parameters.js create mode 100644 prep/passwordCheckerFunction.js create mode 100644 prep/using-a-function.js diff --git a/prep/parameters.js b/prep/parameters.js new file mode 100644 index 000000000..650e29b38 --- /dev/null +++ b/prep/parameters.js @@ -0,0 +1,5 @@ +function greet(timeOfDay, name = "user"){ + console.log(`Good ${timeOfDay}, ${name}.`) +} + +greet("afternoon"); \ No newline at end of file diff --git a/prep/passwordCheckerFunction.js b/prep/passwordCheckerFunction.js new file mode 100644 index 000000000..2373583d4 --- /dev/null +++ b/prep/passwordCheckerFunction.js @@ -0,0 +1,10 @@ +const password = "secretword123"; + +function checkPassword(userInput){ + + return userInput === password; +} + +const toPrint = "The result was: " + checkPassword("secretword123"); +checkPassword("wrongngndn"); +console.log(toPrint); \ No newline at end of file diff --git a/prep/using-a-function.js b/prep/using-a-function.js new file mode 100644 index 000000000..acacb6d03 --- /dev/null +++ b/prep/using-a-function.js @@ -0,0 +1,4 @@ +const rounded = Math.round(10.3); +const rounded2 = Math.round(4.2); +console.log(rounded, rounded2); +console.lo \ No newline at end of file From 0da90b98e76ce86ed766bc59e66cd95b2eb8478f Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Sat, 19 Sep 2026 23:42:14 +0100 Subject: [PATCH 02/13] Solved and explained 0.js in errors --- Sprint-3/1-key-errors/0.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 653d6f5a0..e3cc6ed61 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -1,13 +1,28 @@ // Predict and explain first... // =============> write your prediction here +//Answer: I predict that there will be a Reference Error, because str get's re-declared with let +//inside the function even though it already is declared as it is the parameter. Perhaps it would +// be solved by removing the "let". // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring +/* function capitalise(str) { let str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } +console.log(capitalise("hellllo"); +*/ + // =============> write your explanation here +// Answer: I got a Syntax Error, Identifier 'str' has already been declared. So 'str' needs to not +// be declared again. I will try to write the code without the let // =============> write your new code here + +function capitalise(str) { + str = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; +} +console.log(capitalise("hellllo")); \ No newline at end of file From 73c7f2702300644aef18f171d90ef99d8877905c Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Sat, 19 Sep 2026 23:55:40 +0100 Subject: [PATCH 03/13] Predict, explain and solve 1.js in errors --- Sprint-3/1-key-errors/1.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Sprint-3/1-key-errors/1.js b/Sprint-3/1-key-errors/1.js index f2d56151f..46997f2b9 100644 --- a/Sprint-3/1-key-errors/1.js +++ b/Sprint-3/1-key-errors/1.js @@ -2,9 +2,13 @@ // Why will an error occur when this program runs? // =============> write your prediction here +// Answer: I will get a Syntax Error, because the variable decimalNumber is a parameter +// of the function, and then it gets re-declared inside the function. Removing the +// "const" would make sure it's not re-declared, just value reassigned on that line. // Try playing computer with the example to work out what is going on +/* function convertToPercentage(decimalNumber) { const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; @@ -13,8 +17,26 @@ function convertToPercentage(decimalNumber) { } console.log(decimalNumber); +*/ // =============> write your explanation here +// Answer: I got SyntaxError: Identifier 'decimalNumber' has already been declared +// I will make sure it's not re-declared in the function by removing the "const" + +// After removing the "const" I got a new error. ReferenceError: decimalNumber is not defined. I realized +// that the console.log at the bottom didn't call the function but just logged decimalNumber which hadn't +// been defined in the global scope. Putting back the "const", I will move the declaration of decimalNumber +// to outside the function to make the scope global. Now the global decimalNumber has nothing to do with the +// local parameter decimalNumber in the function. // Finally, correct the code to fix the problem // =============> write your new code here +function convertToPercentage(decimalNumber) { + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} + +const decimalNumber = 0.5; + +console.log(decimalNumber); From cf6d301e08db0d769504345bf3cea1a950566208 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Sun, 20 Sep 2026 12:15:15 +0100 Subject: [PATCH 04/13] Predicted and answered 2.js in errors (and formatted 0.js) --- Sprint-3/1-key-errors/0.js | 2 +- Sprint-3/1-key-errors/2.js | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index e3cc6ed61..4170751bd 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -25,4 +25,4 @@ function capitalise(str) { str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } -console.log(capitalise("hellllo")); \ No newline at end of file +console.log(capitalise("hellllo")); diff --git a/Sprint-3/1-key-errors/2.js b/Sprint-3/1-key-errors/2.js index aad57f7cf..510e7a2c4 100644 --- a/Sprint-3/1-key-errors/2.js +++ b/Sprint-3/1-key-errors/2.js @@ -1,20 +1,38 @@ - // 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 +// Answer: I predict that we will get a Reference Error: num is not defined. Or perhaps an error about the 3, as +// it is a number and therefore not a valid parameter name. I believe perhaps parameter names are like variable +// names and can't start with a number. +/* function square(3) { return num * num; } +*/ // =============> write the error message here +// Answer: SyntaxError: Unexpected number // =============> explain this error message here +// Answer: Yes we got an error message about the number 3. We wouldn't get a message about num not being defined +// since the function isn't called in the code, so the inside of the function can't produce an error. +// I will first try to update the 3 to n3, to see if it is a valid parameter name and see if the error goes away, +// just as an experiment. + +// Answer: The error did go away. However it didn't solve our problem as we still want to receive 3 squared when +// calling the function. I will change n3 to the proper parameter name, num. So it can be referenced inside the +// function body. Then I will make a function call and pass in 3 there, as an argument to the parameter num. +// Then I will log the result to see if it worked. // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} +console.log(square(3)); From 627533f4eac335cf4066041d7810fd2dc1452e53 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Sun, 20 Sep 2026 12:23:26 +0100 Subject: [PATCH 05/13] Predict and solve 0.js in debug --- Sprint-3/2-mandatory-debug/0.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sprint-3/2-mandatory-debug/0.js b/Sprint-3/2-mandatory-debug/0.js index b27511b41..966bab42c 100644 --- a/Sprint-3/2-mandatory-debug/0.js +++ b/Sprint-3/2-mandatory-debug/0.js @@ -1,14 +1,29 @@ // Predict and explain first... // =============> write your prediction here +// Answer: I predict the console will log first 320, and then on a new line "The result of multiplying 10 and 32 is ${NaN}" +// This is because the function logs the result in it's body, so it will log it first as it is run, but +// because it's not explicitly returning anything, it will just return NaN into the string literal logged at the end. +/* function multiply(a, b) { console.log(a * b); } console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); +*/ // =============> write your explanation here +// Answer: In reality, I was almost correct, but the function returned undefined, not NaN, so it logged +// 320, and then The result of multiplying 10 and 32 is undefined. Oh and also of course the string +// interpolation brackets weren't included in the logged string like I had predicted. +// I will fix the problem by returning a * b in the function body, instead of logging it. // Finally, correct the code to fix the problem // =============> write your new code here + +function multiply(a, b) { + return a * b; +} + +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); From c3dada474909c4f1a7bff1f0e9ad7de1aa64e0c9 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Sun, 20 Sep 2026 12:29:04 +0100 Subject: [PATCH 06/13] Predict and solve 1.js in debug --- Sprint-3/2-mandatory-debug/1.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Sprint-3/2-mandatory-debug/1.js b/Sprint-3/2-mandatory-debug/1.js index 37cedfbcf..08bf5e52f 100644 --- a/Sprint-3/2-mandatory-debug/1.js +++ b/Sprint-3/2-mandatory-debug/1.js @@ -1,13 +1,30 @@ // Predict and explain first... // =============> write your prediction here +// Answer: I predict that what happens is `The sum of 10 and 32 is undefined` gets logged to the console. +// That is because even though the function sum has a return statement, it doesn't return anything. There +// is a value that is meant to be returned below the return statement, but because the function already returned +// it will never reach that line in execution. That is why it is greyed out. +/* function sum(a, b) { return; a + b; } console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); +*/ // =============> write your explanation here +// Answer: Running the code logged "The sum of 10 and 32 is undefined" like I thought. I will fix the problem +// by moving a + b; in the function body to be on the same line as return, so it gets returned instead of undefined. + // Finally, correct the code to fix the problem // =============> write your new code here + +function sum(a, b) { + return a + b; +} + +console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); + +// Answer: now "The sum of 10 and 32 is 42" is logged. From 46ff75ca0f1d268822252d53fdd6b38f07089477 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Sun, 20 Sep 2026 12:39:50 +0100 Subject: [PATCH 07/13] Predict and solve 2.js in debug --- Sprint-3/2-mandatory-debug/2.js | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Sprint-3/2-mandatory-debug/2.js b/Sprint-3/2-mandatory-debug/2.js index 57d3f5dc3..0639357bb 100644 --- a/Sprint-3/2-mandatory-debug/2.js +++ b/Sprint-3/2-mandatory-debug/2.js @@ -2,7 +2,11 @@ // Predict the output of the following code: // =============> Write your prediction here +// Answer: I believe that when we run the code we will get a Reference Error, because we are trying to +// call a function getLastDigit with an argument even though the function doesn't have any parameters. +// Or possibly the error might reference num in the function body being undefined. +/* const num = 103; function getLastDigit() { @@ -12,13 +16,46 @@ function getLastDigit() { console.log(`The last digit of 42 is ${getLastDigit(42)}`); console.log(`The last digit of 105 is ${getLastDigit(105)}`); console.log(`The last digit of 806 is ${getLastDigit(806)}`); +*/ // Now run the code and compare the output to your prediction // =============> write the output here +// The last digit of 42 is 3 +// The last digit of 105 is 3 +// The last digit of 806 is 3 + // Explain why the output is the way it is // =============> write your explanation here +// Answer: I was wrong, there was no error message. Instead +// The last digit of 42 is 3 +// The last digit of 105 is 3 +// The last digit of 806 is 3 +// was logged to the console. There was no Reference Error about num being undefined in the function body +// because num IS defined, just above the function and has global scope, so it is reachable by the function. +// Also, no error was thrown due to calling the function with arguments even though it accepted no parameters. +// This is because JavaScript is a dynamic/forgiving language that rather removes surplus information and keeps +// executing the code than stops it and gives an error message. So any surplus arguments passed into a function +// call just gets ignored. That is why the passed arguments have no effect on the function's return value. +// To make them have effect, I will add a parameter to the function, and call it num. Then when num gets accessed +// in the function body, it will not be the value of the global num, but instead the function-local parameter +// num. + // Finally, correct the code to fix the problem // =============> write your new code here +const num = 103; + +function getLastDigit(num) { + return num.toString().slice(-1); +} + +console.log(`The last digit of 42 is ${getLastDigit(42)}`); +console.log(`The last digit of 105 is ${getLastDigit(105)}`); +console.log(`The last digit of 806 is ${getLastDigit(806)}`); + // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem +// Answer: now it works as expected +// The last digit of 42 is 2 +// The last digit of 105 is 5 +// The last digit of 806 is 6 From bc3699418b222a875739d7188213259965e7f28c Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Sun, 20 Sep 2026 12:53:22 +0100 Subject: [PATCH 08/13] Write and test calculateBMI function in 1-bmi.js --- Sprint-3/3-mandatory-implement/1-bmi.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-3/3-mandatory-implement/1-bmi.js b/Sprint-3/3-mandatory-implement/1-bmi.js index 58b1085f1..42b122752 100644 --- a/Sprint-3/3-mandatory-implement/1-bmi.js +++ b/Sprint-3/3-mandatory-implement/1-bmi.js @@ -15,5 +15,15 @@ // It should return a string of their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height + return Number.parseFloat(weight / (height * height)).toFixed(1); } + +// Tests +console.log(calculateBMI(55, 1.63)); +console.log(calculateBMI(120, 1.73)); +console.log(calculateBMI(80, 1.69)); +console.log(calculateBMI(51, 1.55)); + +// Please could I have a little feedback about if I have refactored the function return too much? +// And if so, what is a good guide on how many operations to perform in one line..? I can also +// ask this in class if you prefer. From 303a81a06c442635dc4a00fe84edb12038e18458 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Sun, 20 Sep 2026 22:12:50 +0100 Subject: [PATCH 09/13] Created and tested function toUpperSnakeCase in 2-cases.js --- Sprint-3/3-mandatory-implement/2-cases.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sprint-3/3-mandatory-implement/2-cases.js b/Sprint-3/3-mandatory-implement/2-cases.js index 5b0ef77ad..8d834bde9 100644 --- a/Sprint-3/3-mandatory-implement/2-cases.js +++ b/Sprint-3/3-mandatory-implement/2-cases.js @@ -14,3 +14,12 @@ // You will need to come up with an appropriate name for the function // Use the MDN string documentation to help you find a solution // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase + +function toUpperSnakeCase(str) { + return str.toUpperCase().split(" ").join("_"); +} + +//tests +console.log(toUpperSnakeCase("i want to scream")); +console.log(toUpperSnakeCase("lord of the rings")); +console.log(toUpperSnakeCase("This is a loud file name")); From 5acd69cd9b86e5c95d5d420acc85293a4d72b9d5 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Sun, 20 Sep 2026 22:24:37 +0100 Subject: [PATCH 10/13] Function-ify old code into function toPounds in 3-to-pounds.js --- Sprint-3/3-mandatory-implement/3-to-pounds.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Sprint-3/3-mandatory-implement/3-to-pounds.js b/Sprint-3/3-mandatory-implement/3-to-pounds.js index 10754da73..725a0c73e 100644 --- a/Sprint-3/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-3/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,32 @@ // You will need to declare a function called toPounds with an appropriately named parameter. // You should call this function a number of times to check it works for different inputs + +function 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]; +} + +//tests +let [pounds, pence] = toPounds("399p"); +console.log(`£${pounds}.${pence}`); +[pounds, pence] = toPounds("3995p"); +console.log(`£${pounds}.${pence}`); +[pounds, pence] = toPounds("42895p"); +console.log(`£${pounds}.${pence}`); +[pounds, pence] = toPounds("2p"); +console.log(`£${pounds}.${pence}`); From fb5a7e3033a4cae8900da70223e240290fc161ab Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Sun, 20 Sep 2026 22:40:20 +0100 Subject: [PATCH 11/13] Answer questions in time-format.js --- Sprint-3/4-mandatory-interpret/time-format.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index c0dd9c9a5..39eaa8a60 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -21,18 +21,20 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// Answer: 3 times // 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 +// Answer: 0 // c) What is the return value of pad when it is called for the first time? -// =============> write your answer here +// Answer: "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 +// Answer: 1. Num is 1 in the last call to pad, because the argument sent into pad is remainingSeconds, which is +// 1 because 1 is the remainder after dividing 61 with 60. // 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 +// Answer: "01". The return value is "01" because pad first turned 1 into a string "1", and then used a while loop +// to concatenate (pad) zeros at the start of the "1" string until it became two in length. From 76c016e94ccdf1a8598c3ee8d8db0939cf64384e Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Sun, 20 Sep 2026 23:23:13 +0100 Subject: [PATCH 12/13] Add 4 assert tests and fix the error messages they gave in format-time.js --- Sprint-3/5-stretch-extend/format-time.js | 36 ++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/Sprint-3/5-stretch-extend/format-time.js b/Sprint-3/5-stretch-extend/format-time.js index 32a32e66b..126136c37 100644 --- a/Sprint-3/5-stretch-extend/format-time.js +++ b/Sprint-3/5-stretch-extend/format-time.js @@ -5,7 +5,9 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); if (hours > 12) { - return `${hours - 12}:00 pm`; + return `${hours - 12 < 10 ? "0" : ""}${hours - 12}:${time.slice(-2)} pm`; + } else if (hours === 12) { + return `${time} pm`; } return `${time} am`; } @@ -14,12 +16,40 @@ const currentOutput = formatAs12HourClock("08:00"); const targetOutput = "08:00 am"; console.assert( currentOutput === targetOutput, - `current output: ${currentOutput}, target output: ${targetOutput}` + `current output: ${currentOutput}, target output: ${targetOutput}`, ); const currentOutput2 = formatAs12HourClock("23:00"); const targetOutput2 = "11:00 pm"; console.assert( currentOutput2 === targetOutput2, - `current output: ${currentOutput2}, target output: ${targetOutput2}` + `current output: ${currentOutput2}, target output: ${targetOutput2}`, +); + +const currentOutput3 = formatAs12HourClock("12:00"); +const targetOutput3 = "12:00 pm"; +console.assert( + currentOutput3 === targetOutput3, + `current output: ${currentOutput3}, target output: ${targetOutput3}`, +); + +const currentOutput4 = formatAs12HourClock("15:45"); +const targetOutput4 = "03:45 pm"; +console.assert( + currentOutput4 === targetOutput4, + `current output: ${currentOutput4}, target output: ${targetOutput4}`, +); + +const currentOutput5 = formatAs12HourClock("08:25"); +const targetOutput5 = "08:25 am"; +console.assert( + currentOutput5 === targetOutput5, + `current output: ${currentOutput5}, target output: ${targetOutput5}`, +); + +const currentOutput6 = formatAs12HourClock("12:17"); +const targetOutput6 = "12:17 pm"; +console.assert( + currentOutput6 === targetOutput6, + `current output: ${currentOutput6}, target output: ${targetOutput6}`, ); From 005834efba1b427acc79af59a34eae3d4a34276b Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Sun, 20 Sep 2026 23:32:48 +0100 Subject: [PATCH 13/13] Deleted prep as those files don't belong in the PR --- prep/parameters.js | 5 ----- prep/passwordCheckerFunction.js | 10 ---------- prep/using-a-function.js | 4 ---- 3 files changed, 19 deletions(-) delete mode 100644 prep/parameters.js delete mode 100644 prep/passwordCheckerFunction.js delete mode 100644 prep/using-a-function.js diff --git a/prep/parameters.js b/prep/parameters.js deleted file mode 100644 index 650e29b38..000000000 --- a/prep/parameters.js +++ /dev/null @@ -1,5 +0,0 @@ -function greet(timeOfDay, name = "user"){ - console.log(`Good ${timeOfDay}, ${name}.`) -} - -greet("afternoon"); \ No newline at end of file diff --git a/prep/passwordCheckerFunction.js b/prep/passwordCheckerFunction.js deleted file mode 100644 index 2373583d4..000000000 --- a/prep/passwordCheckerFunction.js +++ /dev/null @@ -1,10 +0,0 @@ -const password = "secretword123"; - -function checkPassword(userInput){ - - return userInput === password; -} - -const toPrint = "The result was: " + checkPassword("secretword123"); -checkPassword("wrongngndn"); -console.log(toPrint); \ No newline at end of file diff --git a/prep/using-a-function.js b/prep/using-a-function.js deleted file mode 100644 index acacb6d03..000000000 --- a/prep/using-a-function.js +++ /dev/null @@ -1,4 +0,0 @@ -const rounded = Math.round(10.3); -const rounded2 = Math.round(4.2); -console.log(rounded, rounded2); -console.lo \ No newline at end of file