From db8bec9be3ad924bc2fb99bce4a72f149d7c3897 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Thu, 24 Sep 2026 23:51:01 +0100 Subject: [PATCH 01/14] Complete Sprint 3 coursework --- Sprint-3/1-key-errors/0.js | 22 +++- Sprint-3/1-key-errors/1.js | 34 +++-- Sprint-3/1-key-errors/2.js | 17 ++- Sprint-3/2-mandatory-debug/0.js | 18 ++- Sprint-3/2-mandatory-debug/1.js | 18 ++- Sprint-3/2-mandatory-debug/2.js | 39 ++++-- Sprint-3/3-mandatory-implement/1-bmi.js | 3 + Sprint-3/3-mandatory-implement/2-cases.js | 6 + Sprint-3/3-mandatory-implement/3-to-pounds.js | 40 ++++++ Sprint-3/4-mandatory-interpret/time-format.js | 25 +++- Sprint-3/5-stretch-extend/format-time.js | 117 +++++++++++++++++- 11 files changed, 296 insertions(+), 43 deletions(-) diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 653d6f5a0..552419761 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -1,13 +1,23 @@ // Predict and explain first... -// =============> write your prediction here +// ======> write your prediction here: I predict that the code should cut out, and make the first letter of the string an uppercase letter, +// then add every letters that comes after // 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; -} +// function capitalise(str) { +// let str= `${str[0].toUpperCase()}${str.slice(1)}` +// return str; +// } + + +// =============> write your explanation here: The error read "SyntaxError: Identifier 'str' has already been declared", +// this is as a result of having two variables with same name. The error occoured in this code because the variable "str" has been decleared twice -// =============> write your explanation here // =============> write your new code here + +function capitalise(str) { + let str2= `${str[0].toUpperCase()}${str.slice(1)}` + return str2; +} +console.log(capitalise("money")) \ No newline at end of file diff --git a/Sprint-3/1-key-errors/1.js b/Sprint-3/1-key-errors/1.js index f2d56151f..6f0b04f61 100644 --- a/Sprint-3/1-key-errors/1.js +++ b/Sprint-3/1-key-errors/1.js @@ -1,20 +1,38 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> write your prediction here +// Answer below: +// A syntax error will occur for two reasons, first because there variable const "decimalNumber" being redecleared +// The second reason is because the function "convertToPercentage" is not called correctly. -// Try playing computer with the example to work out what is going on +// =============> write your prediction here: +// Answer below: +// I predicted that the code will not work because of the variable (decimalNumber) inside the function, +// Also because the console.log(decimalNumber) is just a name that exist inside the function -function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; - const percentage = `${decimalNumber * 100}%`; - return percentage; -} +// Try playing computer with the example to work out what is going on + +// function convertToPercentage(decimalNumber) { +// const decimalNumber = 0.5; +// const percentage = `${decimalNumber * 100}%`; -console.log(decimalNumber); +// return percentage; +// } +// console.log(decimalNumber); // =============> write your explanation here +// Answer: + +// const decimalNumber redeclares the parameter name which causes a SyntaxError. +// also console.log(decimalNumber) outside fails because the parameter only exists inside the function" // Finally, correct the code to fix the problem // =============> write your new code here + +function convertToPercentage(decimalNumber) { + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} +console.log(convertToPercentage(10.5)); \ No newline at end of file diff --git a/Sprint-3/1-key-errors/2.js b/Sprint-3/1-key-errors/2.js index aad57f7cf..3c5f20756 100644 --- a/Sprint-3/1-key-errors/2.js +++ b/Sprint-3/1-key-errors/2.js @@ -1,20 +1,31 @@ // Predict and explain first BEFORE you run any code... +// Answer below: +// The code will not work because the placeholder variable (3) should be an actual name like "num" + // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here -function square(3) { - return num * num; -} +// function square(3) { +// return num * num; +// } // =============> write the error message here +// SyntaxError: Unexpected number // =============> explain this error message here +// The error message explains the error in the function parameter (3), the function expects a name parameter instead of a number. // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} +console.log(square(10)) + + diff --git a/Sprint-3/2-mandatory-debug/0.js b/Sprint-3/2-mandatory-debug/0.js index b27511b41..9216f69ec 100644 --- a/Sprint-3/2-mandatory-debug/0.js +++ b/Sprint-3/2-mandatory-debug/0.js @@ -1,14 +1,24 @@ // Predict and explain first... +// Answer below: +// The code needs a value inside the console.log function to multiply, but no value was useed to replace the placeholder parameters +// It should be an error, no value to return // =============> write your prediction here -function multiply(a, b) { - console.log(a * b); -} +// function multiply(a, b) { +// console.log(a * b); +// } +// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +// Answer below: +// The original logs the product instead of returning it, so the function call inside the template string gives undefined // Finally, correct the code to fix the problem // =============> write your new code here + +function multiply(a, b) { + return a * b +} +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); diff --git a/Sprint-3/2-mandatory-debug/1.js b/Sprint-3/2-mandatory-debug/1.js index 37cedfbcf..800cf59a7 100644 --- a/Sprint-3/2-mandatory-debug/1.js +++ b/Sprint-3/2-mandatory-debug/1.js @@ -1,13 +1,21 @@ // Predict and explain first... // =============> write your prediction here +// Code will not work because the paremeters should be on same line as return -function sum(a, b) { - return; - a + b; -} +// function sum(a, b) { +// return; +// a + b; +// } -console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); +// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +// The errors in this codes is the semi-colon in front of the return and the placeholder parameters not on same line as the return // Finally, correct the code to fix the problem // =============> write your new code here + +function sum(a, b) { + return a + b; +} + +console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); diff --git a/Sprint-3/2-mandatory-debug/2.js b/Sprint-3/2-mandatory-debug/2.js index 57d3f5dc3..4571f53fa 100644 --- a/Sprint-3/2-mandatory-debug/2.js +++ b/Sprint-3/2-mandatory-debug/2.js @@ -2,23 +2,48 @@ // Predict the output of the following code: // =============> Write your prediction here +// Answer below: +// There is a constant variable num with value 103, the code should print last digit of the constant variable. -const num = 103; +// const num = 103; -function getLastDigit() { - return num.toString().slice(-1); -} +// function getLastDigit() { +// return num.toString().slice(-1); +// } -console.log(`The last digit of 42 is ${getLastDigit(42)}`); -console.log(`The last digit of 105 is ${getLastDigit(105)}`); -console.log(`The last digit of 806 is ${getLastDigit(806)}`); +// 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 +// Answer below: +// 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 below: +// The code kept repeating same value for all log because of the constant variable decleared before the function and used inside the function. + // Finally, correct the code to fix the problem // =============> write your new code here +function getLastDigit(num) { + return num.toString().slice(-1); +} + +console.log(`The last digit of 42 is ${getLastDigit(42)}`); +console.log(`The last digit of 105 is ${getLastDigit(105)}`); +console.log(`The last digit of 806 is ${getLastDigit(806)}`); + + // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem + +// Answer below: + +// The global constant variable outside the function has affected the code and caused it to always reference the last number of the global variable +// To fix this, getLastDigit needed its own parameter, so num comes from whatever you pass in \ No newline at end of file diff --git a/Sprint-3/3-mandatory-implement/1-bmi.js b/Sprint-3/3-mandatory-implement/1-bmi.js index 58b1085f1..4b6398b12 100644 --- a/Sprint-3/3-mandatory-implement/1-bmi.js +++ b/Sprint-3/3-mandatory-implement/1-bmi.js @@ -15,5 +15,8 @@ // It should return a string of their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { + const bmi = weight / (height * height) + return bmi.toFixed(1) // return the BMI of someone based off their weight and height } +console.log(`Your BMI is ${calculateBMI(100, 1.62)}`) diff --git a/Sprint-3/3-mandatory-implement/2-cases.js b/Sprint-3/3-mandatory-implement/2-cases.js index 5b0ef77ad..b404d1ea0 100644 --- a/Sprint-3/3-mandatory-implement/2-cases.js +++ b/Sprint-3/3-mandatory-implement/2-cases.js @@ -14,3 +14,9 @@ // You will need to come up with an appropriate name for the function // Use the MDN string documentation to help you find a solution // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase + +function upperCase(str) { + const returnUpperCase = str.toUpperCase().replaceAll(" ", "_") + return returnUpperCase +} +console.log(upperCase("what is your name mr man? ")) \ No newline at end of file diff --git a/Sprint-3/3-mandatory-implement/3-to-pounds.js b/Sprint-3/3-mandatory-implement/3-to-pounds.js index 10754da73..2ca524252 100644 --- a/Sprint-3/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-3/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,43 @@ // You will need to declare a function called toPounds with an appropriately named parameter. // You should call this function a number of times to check it works for different inputs + + +// const penceString = "399p"; + +// const penceStringWithoutTrailingP = penceString.substring( +// 0, +// penceString.length - 1 +// ); + +// const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +// const pounds = paddedPenceNumberString.substring( +// 0, +// paddedPenceNumberString.length - 2 +// ); + +// const pence = paddedPenceNumberString +// .substring(paddedPenceNumberString.length - 2) +// .padEnd(2, "0"); + +// console.log(`£${pounds}.${pence}`); + + +function toPounds(inPounds) { + const penceStringWithoutTrailingP = inPounds.substring( + 0, + inPounds.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("599p")) \ No newline at end of file diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index c0dd9c9a5..58c1dc52b 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -1,11 +1,15 @@ function pad(num) { + // console.log(num) let numString = num.toString(); + // console.log(numString, "numstr") while (numString.length < 2) { numString = "0" + numString; } + // console.log(numString, "FULLNUM") return numString; } + function formatTimeDisplay(seconds) { const remainingSeconds = seconds % 60; const totalMinutes = (seconds - remainingSeconds) / 60; @@ -14,6 +18,10 @@ function formatTimeDisplay(seconds) { return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } +console.log(formatTimeDisplay(61)) + + + // You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit // to help you answer these questions @@ -21,18 +29,27 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> write your answer here +// Answer below: +// Pad runs once for "totalHours", once "remainingMinutes" and once for "remainingSeconds" in total pad is called 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 +// =============> write your answer here +// Answer below: +// The first pad is pad(totalHours) and the value is 0 // c) What is the return value of pad when it is called for the first time? // =============> write your answer here +// The value is 0 plus the "0" added to it to make the value 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 +// =============> write your answer here +// Answer below: +// The last call is pad(remainingSeconds) and the value is 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 +// =============> write your answer here +// Answer below: +// the return value initially is 1 and "0" was added to it in front to make the value 01 diff --git a/Sprint-3/5-stretch-extend/format-time.js b/Sprint-3/5-stretch-extend/format-time.js index 32a32e66b..d7a71c282 100644 --- a/Sprint-3/5-stretch-extend/format-time.js +++ b/Sprint-3/5-stretch-extend/format-time.js @@ -2,24 +2,129 @@ // Make sure to do the prep before you do the coursework // Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. +// function formatAs12HourClock(time) { +// const hours = Number(time.slice(0, 2)); +// if (hours > 12) { +// return `${hours - 12}:00 pm`; +// } +// return `${time} am`; +// } +// // console.log(formatAs12HourClock("10:15")); + +// // Early Morning: ================> assertion passed +// let currentOutput = formatAs12HourClock("08:30"); +// let targetOutput = "08:30 am"; +// console.assert( +// currentOutput === targetOutput, +// `current output: ${currentOutput}, target output: ${targetOutput}` +// ); +// console.log(formatAs12HourClock("08:30")) + +// // Mid-morning ==============> assertion passed +// currentOutput = formatAs12HourClock("10:00"); +// targetOutput = "10:00 am"; +// console.assert( +// currentOutput === targetOutput, +// `current output: ${currentOutput}, target output: ${targetOutput}` +// ); +// console.log(formatAs12HourClock("10.00")) + +// // Late morning ============> assertion passed +// currentOutput = formatAs12HourClock("11:45"); +// targetOutput = "11:45 am"; +// console.assert( +// currentOutput === targetOutput, +// `current output: ${currentOutput}, target output: ${targetOutput}` +// ); +// console.log(formatAs12HourClock("11.45")) + + +// // Afternoon =============> assertion failed +// let currentOutput2 = formatAs12HourClock("12:00"); +// let targetOutput2 = "12:00 pm"; +// console.assert( +// currentOutput2 === targetOutput2, +// `current output: ${currentOutput2}, target output: ${targetOutput2}` +// ); +// console.log(formatAs12HourClock("12:00")) + +// // Early afternoon =============> assertion passed +// currentOutput2 = formatAs12HourClock("14:00"); +// targetOutput2 = "02:00 pm"; +// console.assert( +// currentOutput2 === targetOutput2, +// `current output: ${currentOutput2}, target output: ${targetOutput2}` +// ); +// console.log(formatAs12HourClock("14:00")) + +// // Mid afternoon =============> time display doesn't correspond +// currentOutput2 = formatAs12HourClock("15:30"); +// targetOutput2 = "03:30 pm"; +// console.assert( +// currentOutput2 === targetOutput2, +// `current output: ${currentOutput2}, target output: ${targetOutput2}` +// ); +// console.log(formatAs12HourClock("15:30")) + +// // Towards evening ==============> time display doesn't correspond +// currentOutput2 = formatAs12HourClock("17:30"); +// targetOutput2 = "05:30 pm"; +// console.assert( +// currentOutput2 === targetOutput2, +// `current output: ${currentOutput2}, target output: ${targetOutput2}` +// ); +// console.log(formatAs12HourClock("17:30")) + +// // Late night =============> assertion passed +// currentOutput2 = formatAs12HourClock("23:00"); +// targetOutput2 = "11:00 pm"; +// console.assert( +// currentOutput2 === targetOutput2, +// `current output: ${currentOutput2}, target output: ${targetOutput2}` +// ); +// console.log(formatAs12HourClock("23:00")) + + +// Test result: +// Hours and Minutes worked in the AM function for different time test. +// 12:00 in the afternoon doesn't function correctly +// 00:00 mid-night doesnt work +// Minutes in the PM are not working. + +// To fix bug: + function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); + const minutes = time.slice(3, 5); + + if (hours === 0) { + return `12:${minutes} am` + } + if (hours === 12) { + return `12:${minutes} pm`; + } if (hours > 12) { - return `${hours - 12}:00 pm`; + return `${hours - 12}:${minutes} pm`; } + + return `${time} am`; } -const currentOutput = formatAs12HourClock("08:00"); -const targetOutput = "08:00 am"; +const currentOutput = formatAs12HourClock("01:00"); +const targetOutput = "01:00 am"; console.assert( currentOutput === targetOutput, - `current output: ${currentOutput}, target output: ${targetOutput}` + `current output: ${currentOutput}, target output: ${targetOutput}` ); +console.log(formatAs12HourClock("01:00")) + +const currentOutput2 = formatAs12HourClock("19:30"); +const targetOutput2 = "7:30 pm"; -const currentOutput2 = formatAs12HourClock("23:00"); -const targetOutput2 = "11:00 pm"; console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +console.log(formatAs12HourClock("19:30")); From af89dc0358b98418eecc6c110ea12266a3743a47 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sat, 26 Sep 2026 09:48:40 +0100 Subject: [PATCH 02/14] simplified task o.js --- Sprint-3/1-key-errors/0.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 552419761..8834fd1b8 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -17,7 +17,8 @@ // =============> write your new code here function capitalise(str) { - let str2= `${str[0].toUpperCase()}${str.slice(1)}` - return str2; +// let str2= `${str[0].toUpperCase()}${str.slice(1)}` +// return str2 + return str2= `${str[0].toUpperCase()}${str.slice(1)}`; } console.log(capitalise("money")) \ No newline at end of file From f919f28aaa18d31b12e37f0018d9b20d923077d6 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Tue, 29 Sep 2026 18:27:06 +0100 Subject: [PATCH 03/14] fix str function --- Sprint-3/1-key-errors/0.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 8834fd1b8..6e35dece7 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -17,8 +17,6 @@ // =============> write your new code here function capitalise(str) { -// let str2= `${str[0].toUpperCase()}${str.slice(1)}` -// return str2 - return str2= `${str[0].toUpperCase()}${str.slice(1)}`; + return str= `${str[0].toUpperCase()}${str.slice(1)}`; } console.log(capitalise("money")) \ No newline at end of file From a56fa7ffbc21376771e7bc0a686217d54b648bf3 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Tue, 29 Sep 2026 18:33:54 +0100 Subject: [PATCH 04/14] comments rephrased --- Sprint-3/1-key-errors/0.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 6e35dece7..87a7a40a4 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -1,22 +1,24 @@ // Predict and explain first... -// ======> write your prediction here: I predict that the code should cut out, and make the first letter of the string an uppercase letter, +// ======> write your prediction here: +// Answer below: + +// I predict that the code should make the first letter of the string an uppercase letter, // then add every letters that comes after // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring -// function capitalise(str) { -// let str= `${str[0].toUpperCase()}${str.slice(1)}` -// return str; -// } +// =============> write your explanation here: +// Answer below: -// =============> write your explanation here: The error read "SyntaxError: Identifier 'str' has already been declared", -// this is as a result of having two variables with same name. The error occoured in this code because the variable "str" has been decleared twice +// The error read "SyntaxError: Identifier 'str' has already been declared", +// This is as a result of having two variables with same name "str". +// The error occoured in this code because the variable "str" has been declared twice // =============> write your new code here function capitalise(str) { return str= `${str[0].toUpperCase()}${str.slice(1)}`; } -console.log(capitalise("money")) \ No newline at end of file +console.log(capitalise("money")); \ No newline at end of file From 7a68faf6a0ff8fcfb0e5d8f9638f22b1b907ded6 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Tue, 29 Sep 2026 18:40:24 +0100 Subject: [PATCH 05/14] format code using prettier --- Sprint-3/3-mandatory-implement/3-to-pounds.js | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/Sprint-3/3-mandatory-implement/3-to-pounds.js b/Sprint-3/3-mandatory-implement/3-to-pounds.js index 2ca524252..0c768546d 100644 --- a/Sprint-3/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-3/3-mandatory-implement/3-to-pounds.js @@ -5,7 +5,6 @@ // You should call this function a number of times to check it works for different inputs - // const penceString = "399p"; // const penceStringWithoutTrailingP = penceString.substring( @@ -25,22 +24,21 @@ // console.log(`£${pounds}.${pence}`); - function toPounds(inPounds) { - const penceStringWithoutTrailingP = inPounds.substring( - 0, - inPounds.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}`; + const penceStringWithoutTrailingP = inPounds.substring( + 0, + inPounds.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("599p")) \ No newline at end of file +console.log(toPounds("599p")); From 29644dfd5783248922c673384177f74ee72682c0 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Tue, 29 Sep 2026 18:42:34 +0100 Subject: [PATCH 06/14] add semi-colons to lines --- Sprint-3/3-mandatory-implement/2-cases.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-3/3-mandatory-implement/2-cases.js b/Sprint-3/3-mandatory-implement/2-cases.js index b404d1ea0..fec88089b 100644 --- a/Sprint-3/3-mandatory-implement/2-cases.js +++ b/Sprint-3/3-mandatory-implement/2-cases.js @@ -16,7 +16,7 @@ // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase function upperCase(str) { - const returnUpperCase = str.toUpperCase().replaceAll(" ", "_") - return returnUpperCase + const returnUpperCase = str.toUpperCase().replaceAll(" ", "_"); + return returnUpperCase; } -console.log(upperCase("what is your name mr man? ")) \ No newline at end of file +console.log(upperCase("what is your name mr man? ")); \ No newline at end of file From 82f391f3d27662372b5deb5a46de49769c9f0728 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Tue, 29 Sep 2026 19:17:35 +0100 Subject: [PATCH 07/14] time-format deleted all unwanted comment --- Sprint-3/4-mandatory-interpret/time-format.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index 58c1dc52b..a091173cf 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -1,11 +1,9 @@ function pad(num) { - // console.log(num) let numString = num.toString(); - // console.log(numString, "numstr") + while (numString.length < 2) { numString = "0" + numString; } - // console.log(numString, "FULLNUM") return numString; } From da4a942b882323379abad598a2cf6cfc1194d78a Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Tue, 29 Sep 2026 19:27:03 +0100 Subject: [PATCH 08/14] padStart used and deleted unwanted comments --- Sprint-3/4-mandatory-interpret/time-format.js | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index a091173cf..b5f0cd22e 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -1,13 +1,6 @@ function pad(num) { - let numString = num.toString(); - - while (numString.length < 2) { - numString = "0" + numString; - } - return numString; + return num.toString().padStart(2, "0"); } - - function formatTimeDisplay(seconds) { const remainingSeconds = seconds % 60; const totalMinutes = (seconds - remainingSeconds) / 60; @@ -16,10 +9,7 @@ function formatTimeDisplay(seconds) { return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } -console.log(formatTimeDisplay(61)) - - - +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 @@ -27,14 +17,14 @@ console.log(formatTimeDisplay(61)) // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> write your answer here // Answer below: // Pad runs once for "totalHours", once "remainingMinutes" and once for "remainingSeconds" in total pad is called 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 +// =============> write your answer here // Answer below: // The first pad is pad(totalHours) and the value is 0 @@ -43,11 +33,11 @@ console.log(formatTimeDisplay(61)) // The value is 0 plus the "0" added to it to make the value 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 +// =============> write your answer here // Answer below: // The last call is pad(remainingSeconds) and the value is 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 +// =============> write your answer here // Answer below: // the return value initially is 1 and "0" was added to it in front to make the value 01 From 6b0f9f4efebab89b7798e10b9681458ed6c7d917 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Tue, 29 Sep 2026 19:29:21 +0100 Subject: [PATCH 09/14] padStart used and deleted unwanted comments --- Sprint-3/4-mandatory-interpret/time-format.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index b5f0cd22e..47e66b421 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -30,7 +30,7 @@ console.log(formatTimeDisplay(61)); // c) What is the return value of pad when it is called for the first time? // =============> write your answer here -// The value is 0 plus the "0" added to it to make the value 00 +// The value is 0 plus the "0" added to it to make the value "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 From a1a3870fe0ff0a5b7ef2945ddad9292099541f5d Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Tue, 29 Sep 2026 19:45:25 +0100 Subject: [PATCH 10/14] format.js --- Sprint-3/5-stretch-extend/format-time.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-3/5-stretch-extend/format-time.js b/Sprint-3/5-stretch-extend/format-time.js index d7a71c282..7c7bc0dd9 100644 --- a/Sprint-3/5-stretch-extend/format-time.js +++ b/Sprint-3/5-stretch-extend/format-time.js @@ -104,7 +104,7 @@ function formatAs12HourClock(time) { return `12:${minutes} pm`; } if (hours > 12) { - return `${hours - 12}:${minutes} pm`; + return `${String(hours - 12).padStart(2, "0")}:${minutes} pm`; } @@ -120,7 +120,7 @@ console.assert( console.log(formatAs12HourClock("01:00")) const currentOutput2 = formatAs12HourClock("19:30"); -const targetOutput2 = "7:30 pm"; +const targetOutput2 = "07:30 pm"; console.assert( currentOutput2 === targetOutput2, From 5e0afc9134530fa245a61f5b7d8fa7e266cd7df6 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Tue, 29 Sep 2026 19:46:48 +0100 Subject: [PATCH 11/14] format.js --- Sprint-3/5-stretch-extend/format-time.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Sprint-3/5-stretch-extend/format-time.js b/Sprint-3/5-stretch-extend/format-time.js index 7c7bc0dd9..58c1dd45d 100644 --- a/Sprint-3/5-stretch-extend/format-time.js +++ b/Sprint-3/5-stretch-extend/format-time.js @@ -8,7 +8,7 @@ // return `${hours - 12}:00 pm`; // } // return `${time} am`; -// } +// } // // console.log(formatAs12HourClock("10:15")); // // Early Morning: ================> assertion passed @@ -38,7 +38,6 @@ // ); // console.log(formatAs12HourClock("11.45")) - // // Afternoon =============> assertion failed // let currentOutput2 = formatAs12HourClock("12:00"); // let targetOutput2 = "12:00 pm"; @@ -84,7 +83,6 @@ // ); // console.log(formatAs12HourClock("23:00")) - // Test result: // Hours and Minutes worked in the AM function for different time test. // 12:00 in the afternoon doesn't function correctly @@ -98,7 +96,7 @@ function formatAs12HourClock(time) { const minutes = time.slice(3, 5); if (hours === 0) { - return `12:${minutes} am` + return `12:${minutes} am`; } if (hours === 12) { return `12:${minutes} pm`; @@ -106,7 +104,6 @@ function formatAs12HourClock(time) { if (hours > 12) { return `${String(hours - 12).padStart(2, "0")}:${minutes} pm`; } - return `${time} am`; } @@ -115,16 +112,16 @@ const currentOutput = formatAs12HourClock("01:00"); const targetOutput = "01:00 am"; console.assert( currentOutput === targetOutput, - `current output: ${currentOutput}, target output: ${targetOutput}` + `current output: ${currentOutput}, target output: ${targetOutput}`, ); -console.log(formatAs12HourClock("01:00")) +console.log(formatAs12HourClock("01:00")); const currentOutput2 = formatAs12HourClock("19:30"); const targetOutput2 = "07:30 pm"; console.assert( currentOutput2 === targetOutput2, - `current output: ${currentOutput2}, target output: ${targetOutput2}` + `current output: ${currentOutput2}, target output: ${targetOutput2}`, ); console.log(formatAs12HourClock("19:30")); From cafd4e7f34858634bff4a8fc9adbcf74ed1efa09 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Tue, 29 Sep 2026 19:54:59 +0100 Subject: [PATCH 12/14] format.js --- Sprint-3/5-stretch-extend/format-time.js | 85 +----------------------- 1 file changed, 1 insertion(+), 84 deletions(-) diff --git a/Sprint-3/5-stretch-extend/format-time.js b/Sprint-3/5-stretch-extend/format-time.js index 58c1dd45d..87f359f0f 100644 --- a/Sprint-3/5-stretch-extend/format-time.js +++ b/Sprint-3/5-stretch-extend/format-time.js @@ -1,92 +1,9 @@ -// This is the latest solution to the problem from the prep. -// Make sure to do the prep before you do the coursework -// Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. -// function formatAs12HourClock(time) { -// const hours = Number(time.slice(0, 2)); -// if (hours > 12) { -// return `${hours - 12}:00 pm`; -// } -// return `${time} am`; -// } -// // console.log(formatAs12HourClock("10:15")); - -// // Early Morning: ================> assertion passed -// let currentOutput = formatAs12HourClock("08:30"); -// let targetOutput = "08:30 am"; -// console.assert( -// currentOutput === targetOutput, -// `current output: ${currentOutput}, target output: ${targetOutput}` -// ); -// console.log(formatAs12HourClock("08:30")) - -// // Mid-morning ==============> assertion passed -// currentOutput = formatAs12HourClock("10:00"); -// targetOutput = "10:00 am"; -// console.assert( -// currentOutput === targetOutput, -// `current output: ${currentOutput}, target output: ${targetOutput}` -// ); -// console.log(formatAs12HourClock("10.00")) - -// // Late morning ============> assertion passed -// currentOutput = formatAs12HourClock("11:45"); -// targetOutput = "11:45 am"; -// console.assert( -// currentOutput === targetOutput, -// `current output: ${currentOutput}, target output: ${targetOutput}` -// ); -// console.log(formatAs12HourClock("11.45")) - -// // Afternoon =============> assertion failed -// let currentOutput2 = formatAs12HourClock("12:00"); -// let targetOutput2 = "12:00 pm"; -// console.assert( -// currentOutput2 === targetOutput2, -// `current output: ${currentOutput2}, target output: ${targetOutput2}` -// ); -// console.log(formatAs12HourClock("12:00")) - -// // Early afternoon =============> assertion passed -// currentOutput2 = formatAs12HourClock("14:00"); -// targetOutput2 = "02:00 pm"; -// console.assert( -// currentOutput2 === targetOutput2, -// `current output: ${currentOutput2}, target output: ${targetOutput2}` -// ); -// console.log(formatAs12HourClock("14:00")) - -// // Mid afternoon =============> time display doesn't correspond -// currentOutput2 = formatAs12HourClock("15:30"); -// targetOutput2 = "03:30 pm"; -// console.assert( -// currentOutput2 === targetOutput2, -// `current output: ${currentOutput2}, target output: ${targetOutput2}` -// ); -// console.log(formatAs12HourClock("15:30")) - -// // Towards evening ==============> time display doesn't correspond -// currentOutput2 = formatAs12HourClock("17:30"); -// targetOutput2 = "05:30 pm"; -// console.assert( -// currentOutput2 === targetOutput2, -// `current output: ${currentOutput2}, target output: ${targetOutput2}` -// ); -// console.log(formatAs12HourClock("17:30")) - -// // Late night =============> assertion passed -// currentOutput2 = formatAs12HourClock("23:00"); -// targetOutput2 = "11:00 pm"; -// console.assert( -// currentOutput2 === targetOutput2, -// `current output: ${currentOutput2}, target output: ${targetOutput2}` -// ); -// console.log(formatAs12HourClock("23:00")) // Test result: // Hours and Minutes worked in the AM function for different time test. // 12:00 in the afternoon doesn't function correctly -// 00:00 mid-night doesnt work +// 00:00 mid-night doesn't work // Minutes in the PM are not working. // To fix bug: From 7c9837f36060fe6e67ed279988a1465a257fdd19 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Tue, 29 Sep 2026 20:29:59 +0100 Subject: [PATCH 13/14] 0.js task completed --- Sprint-3/1-key-errors/0.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 87a7a40a4..03f051a8a 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -19,6 +19,6 @@ // =============> write your new code here function capitalise(str) { - return str= `${str[0].toUpperCase()}${str.slice(1)}`; + return str = `${str[0].toUpperCase()}${str.slice(1)}`; } console.log(capitalise("money")); \ No newline at end of file From 20a688e5027be6b3ef13d4adeaaf93a3dc04b709 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Tue, 29 Sep 2026 22:21:04 +0100 Subject: [PATCH 14/14] fix: correct return statement in capitalise function --- Sprint-3/1-key-errors/0.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 03f051a8a..ec0bd8fbe 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -19,6 +19,6 @@ // =============> write your new code here function capitalise(str) { - return str = `${str[0].toUpperCase()}${str.slice(1)}`; + return `${str[0].toUpperCase()}${str.slice(1)}`; } console.log(capitalise("money")); \ No newline at end of file