From 185dbff6bc0705d301cc603a6ba59612ffb9f028 Mon Sep 17 00:00:00 2001 From: Pinx-pinx Date: Sat, 25 Oct 2025 11:27:43 +0200 Subject: [PATCH 01/12] add new var name --- Sprint-2/1-key-errors/0.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..8b8d93022 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,6 +1,5 @@ // Predict and explain first... -// =============> write your prediction here - +// we are expecting the code to return a string with the first character being capitalised. // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring @@ -9,5 +8,13 @@ function capitalise(str) { return str; } -// =============> write your explanation here -// =============> write your new code here +// While calling the function it gave an error "SyntaxError" Identifier 'str' has already been declared " This means that in the code we redeclared a variable name that has been already cleared which is not acceptable in javascript because it cause a naming conflict. +// To fix this we have to change the "let str" into another variable name like " let capitaliseStr" or we can reasign the variable. +// function capitalise(str) { +// let capitaliseStr = `${str[0].toUpperCase()}${str.slice(1)}`; +//return capitaliseStr;} + +//console.log(capitaliseStr("hello")) + + + From 69e8e04d001014b26a982f688473aad55d6ccc92 Mon Sep 17 00:00:00 2001 From: Pinx-pinx Date: Sat, 25 Oct 2025 12:00:56 +0200 Subject: [PATCH 02/12] fixin error --- Sprint-2/1-key-errors/1.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..938718a82 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,12 +1,11 @@ // Predict and explain first... +// This code should return a percentage value but there are errors in the code wo it wil not work. // Why will an error occur when this program runs? -// =============> write your prediction here - // Try playing computer with the example to work out what is going on function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; + const decimalNumber= 0.5; const percentage = `${decimalNumber * 100}%`; return percentage; @@ -14,7 +13,17 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); -// =============> write your explanation here +// The error is the parameter "decimalNumber" has been redeclared as a variable which cause a naming conflict. +//Because the code redeclares a new constant with the same name as the parameter, the argument passed to the function is ignored. +// Next error is is the console.log(decimalNumber), In here you cannot acces a declaredvariale inside a local frame from a global frame + // Finally, correct the code to fix the problem -// =============> write your new code here + +// function convertToPercentage(decimalNumber) { +//const percentage = `${decimalNumber * 100}%`; +//return percentage; +//} +//Cons result = convertToPercentage(0.5) + +//console.log(result); From a976faba182f7924d8db80c4e2c0477847b50e29 Mon Sep 17 00:00:00 2001 From: Pinx-pinx Date: Sat, 25 Oct 2025 12:35:06 +0200 Subject: [PATCH 03/12] fix syntax and ref error --- Sprint-2/1-key-errors/2.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..02a38d332 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -3,18 +3,24 @@ // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here - +// We will get an error because we've given the function parameter a (literal value) which is 3 and not a (identifier)parameter name so this will give us a syntax error. +// Next is we are trying to return num * num which has not been declared locally so it will give us an error. function square(3) { return num * num; } -// =============> write the error message here - -// =============> explain this error message here +//The errors would be +// syntax error and +//reference error. +// Syntax error- the identifier should be a literal value,it should be parameter name +//reference error - the num* num has not been declared locally // Finally, correct the code to fix the problem -// =============> write your new code here +//function square(number){ +//return number * number +//} +//cosole.log(square(3)) + From 76265c73b0c458fc2749b68b6a6b0924ef1a234e Mon Sep 17 00:00:00 2001 From: Pinx-pinx Date: Sat, 25 Oct 2025 13:25:05 +0200 Subject: [PATCH 04/12] add explanation --- Sprint-2/2-mandatory-debug/0.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..c6a91d3e1 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,6 @@ // Predict and explain first... -// =============> write your prediction here +// In this code we are supposed to have a result of multiplying a and b value but there are errors in tthis code. function multiply(a, b) { console.log(a * b); @@ -8,7 +8,16 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// =============> write your explanation here +// This function takes 2 parameters and logs the product of a * b inside the function. +// console.log(a * b) will print the product immediately inside the function, +// but it does not return a value to the caller. +// Therefore, using multiply(10, 32) inside a template literal shows undefined, +// because the function must return a value for the template literal to display it. +/ +/ Finally, correct the code to fix the problem + // function multiply (a,b){ + + // return a*b; + // } -// Finally, correct the code to fix the problem -// =============> write your new code here + // console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); \ No newline at end of file From 8c1ef60119b15901974ae244168094e7753f9a31 Mon Sep 17 00:00:00 2001 From: Pinx-pinx Date: Sat, 25 Oct 2025 13:40:12 +0200 Subject: [PATCH 05/12] explain and fix error --- Sprint-2/2-mandatory-debug/1.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..778104451 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,5 @@ // Predict and explain first... -// =============> write your prediction here +// This code should return a value of adding a and b but this code has an error function sum(a, b) { return; @@ -8,6 +8,15 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); -// =============> write your explanation here -// Finally, correct the code to fix the problem -// =============> write your new code here +// The function sum takes 2 parameter +//return; was used as statement without a value so the return is undefined. +//a+b; will not run because it comes after return +// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); using th function as a template literal will give you undefined since 10+32 was never executed + +// // Finally, correct the code to fix the problem + +// function sum(a,b){ + +// return a+b +// } + // console.log(`The sum of 10 and 32 is ${sum(10, 32)}`) \ No newline at end of file From c3671d0a5e20cf25858f0f6b38db08513c39d873 Mon Sep 17 00:00:00 2001 From: Pinx-pinx Date: Sat, 25 Oct 2025 14:07:44 +0200 Subject: [PATCH 06/12] add parameter,remove cons var --- Sprint-2/2-mandatory-debug/2.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..eb712d354 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,7 +1,13 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// In this code we are supposed to get the last digit of the given argument but it will give an error +//because the variable was declared constant so it will ignore the argument given and also the function getLastDigit was not given a parameter so it will not take any argument +// return num.toString().slice(-1); - .slice works on strings and arrays, so here we convert the number to a string so that .slice(-1) works +//the output you will always get is +//The last digit of 42 is 3 +//The last digit of 105 is 3 +//The last digit of 806 is 3 const num = 103; @@ -14,11 +20,22 @@ 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 +// I run the code and the output is the same as my prediction +// the output you will always get is +//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 +// The output is the way it is because first there was a costant variable declared which 103 +// Then also the function was not give a parameter name so it will not take any argumentt. // 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 From 2a577fe72636a42d0211e1772c5e0f8c16b3ee81 Mon Sep 17 00:00:00 2001 From: Pinx-pinx Date: Sat, 25 Oct 2025 14:29:35 +0200 Subject: [PATCH 07/12] calculate BMI --- Sprint-2/3-mandatory-implement/1-bmi.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..052df91ac 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,10 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { + + let bmiValue = weight/(height**2) + return bmiValue.toFixed(1) +} + +console.log(calculateBMI(70,1.73)) // return the BMI of someone based off their weight and height -} \ No newline at end of file From bdbe2f750060792abe9834f2181dcb6ad668af55 Mon Sep 17 00:00:00 2001 From: Pinx-pinx Date: Sat, 25 Oct 2025 14:50:10 +0200 Subject: [PATCH 08/12] to use toUpperCase and replace --- Sprint-2/3-mandatory-implement/2-cases.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..53eada056 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/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){ + let capitaliseWord = str.toUpperCase().replace(/ /g, '_') + +return capitaliseWord} + + console.log(toUpperSnakeCase("hello there")) + console.log(toUpperSnakeCase("lord of the rings")) + + \ No newline at end of file From 53d40def20c1d697134f614b2457d01c7b15c850 Mon Sep 17 00:00:00 2001 From: Pinx-pinx Date: Sat, 25 Oct 2025 21:29:05 +0200 Subject: [PATCH 09/12] add reusable block of code --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..22da604b9 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,20 @@ // 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}`; +} + +console.log(toPounds("399p")); +console.log(toPounds("5p")); +console.log(toPounds("1250p")); From 504cccf64ad3a9bb6aa732d6eab41bf5dd276d0e Mon Sep 17 00:00:00 2001 From: Pinx-pinx Date: Sat, 25 Oct 2025 22:17:13 +0200 Subject: [PATCH 10/12] add answer to questions --- Sprint-2/4-mandatory-interpret/time-format.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..bd8e410f3 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -10,6 +10,7 @@ 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 @@ -17,18 +18,21 @@ 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: num = 0 // c) What is the return value of pad 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 : return value0 =1 +// Explanation: num = 1 when pad is called for the last time because this corresponds to remainingSeconds. +// Since num is a number, num.toString() converts it to the string "1". +// Then, .padStart(2, "0") ensures the string is at least 2 characters long, so a "0" is added before "1", giving "01". // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> write your answer here +//Answer: return value01 +//Explanation: The pad function always returns a string of at least 2 characters. Since the last call’s num was 1, it becomes "01" after padding. \ No newline at end of file From 2daa6327d9beec08045f2041aa627efa205eb769 Mon Sep 17 00:00:00 2001 From: Pinx-pinx Date: Sat, 25 Oct 2025 23:25:29 +0200 Subject: [PATCH 11/12] add edge cases --- Sprint-2/5-stretch-extend/format-time.js | 40 ++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..93054d4a7 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -4,12 +4,25 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); - if (hours > 12) { - return `${hours - 12}:00 pm`; + const minutes = time.slice(3, 5); + + let displayHours = hours; + let period = "am"; + + if (hours === 0) { + displayHours = 12; // Midnight + } else if (hours === 12) { + period = "pm"; // Noon + } else if (hours > 12) { + displayHours = hours - 12; + period = "pm"; } - return `${time} am`; + + const displayHoursStr = displayHours.toString().padStart(2, "0"); + return `${displayHoursStr}:${minutes} ${period}`; } +// Individual console.assert tests like your original code const currentOutput = formatAs12HourClock("08:00"); const targetOutput = "08:00 am"; console.assert( @@ -23,3 +36,24 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +const currentOutput3 = formatAs12HourClock("12:30"); +const targetOutput3 = "12:30 pm"; +console.assert( + currentOutput3 === targetOutput3, + `current output: ${currentOutput3}, target output: ${targetOutput3}` +); + +const currentOutput4 = formatAs12HourClock("00:15"); +const targetOutput4 = "12:15 am"; +console.assert( + currentOutput4 === targetOutput4, + `current output: ${currentOutput4}, target output: ${targetOutput4}` +); + +const currentOutput5 = formatAs12HourClock("13:45"); +const targetOutput5 = "01:45 pm"; +console.assert( + currentOutput5 === targetOutput5, + `current output: ${currentOutput5}, target output: ${targetOutput5}` +); From 7f3eb3af7c88df3edc8ec330ea401066ac0ab6af Mon Sep 17 00:00:00 2001 From: Pinx-pinx Date: Sat, 25 Oct 2025 23:25:55 +0200 Subject: [PATCH 12/12] add edge cases --- Sprint-2/5-stretch-extend/format-time.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 93054d4a7..70c76295c 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -22,7 +22,7 @@ function formatAs12HourClock(time) { return `${displayHoursStr}:${minutes} ${period}`; } -// Individual console.assert tests like your original code + const currentOutput = formatAs12HourClock("08:00"); const targetOutput = "08:00 am"; console.assert(