From 62dc90f0d4fb9e09ad1aea8648d5ba4da1da5cfd Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Mon, 23 Feb 2026 18:44:27 +0000 Subject: [PATCH 01/10] Fixed redeclaration error in capitalise function Updated variable name to avoid redeclaration error. --- Sprint-2/1-key-errors/0.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..9c6bf3286 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,22 @@ // Predict and explain first... -// =============> write your prediction here +// =============> write your prediction here: We'll get an error message because "str" paramater has been declared already, +//using it again inside the function will clash due to redaclaration. // 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: Identifier 'str' has already been declared, +//redaclaration in the same scope throws up the error message +// =============> write your new code here: function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; - return str; + let newStr = `${str[0].toUpperCase()}${str.slice(1)}`; + return newStr; } -// =============> write your explanation here -// =============> write your new code here +//Above code works because we have used another variable "newStr", avoiding redeclaration. + From 1eea298852beb893e22da8f3429a289c7a8aebcf Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Mon, 2 Mar 2026 07:23:49 +0000 Subject: [PATCH 02/10] Fix redeclaration error and update console.log Removed redeclaration of decimalNumber and updated console.log to call the function. --- Sprint-2/1-key-errors/1.js | 43 +++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..09e0515bc 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,20 +1,47 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> write your prediction here +// =============> write your prediction here: potential error, decimalNumber has already been declared, can't redaclare it again with a new variable in the same scope. +//another error could be, console.log will try to access a local variable from the global scope. // Try playing computer with the example to work out what is going on +// step one: function convertToPercentage(decimalNumber) +// function created with a parameter named (decimalNumber) +// step two: const decimalNumber = 0.5; +// error occurs because decimalNumber has been declared already in the fucntion, cannot declare another one with the same name , in the same scope. +// program stops. +// we have fixed the first error. Code runs again. +// step three: const percentage = `${decimalNumber * 100}%`; +// new variable called percentage created, then the JS code is inserted, where decimalNumber is multiplied by 100. +// no errors here +// step four: return percentage; +// this line sends the value out of the function then stops the function. No errors so far. +// Step five: console.log(decimalNumber); +// error occurs again, because the value created in step four can't be stored in console.log, due to decimalNumber being a parameter inside the function. Outside the function +// there is no variable named decimalNumber. +// we have fixed console.log with (convertToPercentage(0.5), now the result will print properly. + + + +//function convertToPercentage(decimalNumber) { +// const decimalNumber = 0.5; +// const percentage = `${decimalNumber * 100}%`; + +// return percentage; +//} + +//console.log(decimalNumber); + +// =============> write your explanation here: my error predictions turned out to be true and i have played computer with js code to further illustrate my reasoning. + +// Finally, correct the code to fix the problem +// =============> write your new code here: + function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; - return percentage; } -console.log(decimalNumber); - -// =============> write your explanation here +console.log(convertToPercentage(0.5)); -// Finally, correct the code to fix the problem -// =============> write your new code here From 02c8367a275522b201c5863353fe7a622b9864e9 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Mon, 2 Mar 2026 07:43:06 +0000 Subject: [PATCH 03/10] Fix square function parameter and return statement Corrected the square function to use a valid parameter name and return the square of the input. --- Sprint-2/1-key-errors/2.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..0e48e4c4e 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -3,18 +3,30 @@ // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here +// =============> write your prediction of the error here: error one, 3 cannot be a parameter name, parameters must be variable names, not values. +// Error two, num is not defined. There is no variable named num, it would need to match the name inside the function. -function square(3) { - return num * num; -} +//function square(3) { +// return num * num; +//} + +// =============> write the error message here: + +//Uncaught SyntaxError: Unexpected number -// =============> write the error message here +//Uncaught SyntaxError: Illegal return statement -// =============> explain this error message here +// =============> explain this error message here: + +// first error message came up because JS found a number instead of a variable for the function. +// second error message came up because in JS return has to be inside of a function. // Finally, correct the code to fix the problem -// =============> write your new code here +// =============> write your new code here: + +function square(num) { + return num * num; +} From a10df18fdd45bbbbace7a110350bc8b851663629 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Mon, 2 Mar 2026 07:57:58 +0000 Subject: [PATCH 04/10] erased first console.log and replaced it with 'return' to properly log the result. Changed console.log to return in multiply function to fix undefined error. --- Sprint-2/2-mandatory-debug/0.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..86a688e74 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,14 +1,23 @@ // Predict and explain first... -// =============> write your prediction here +// =============> write your prediction here: there will be an error, due to console.log being used incorrectly. Console.log is for displaying but there is no return command to +//clarify what to send to console.log + +//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: I have run the code on node.js and got 'undefined' as an error message. I shall add 'return' instead of the first 'console.log' +//so that the result can be displayed properly in the second console.log. + +// Finally, correct the code to fix the problem +// =============> write your new code here: function multiply(a, b) { - console.log(a * b); + return a * b; } console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// =============> write your explanation here - -// Finally, correct the code to fix the problem -// =============> write your new code here From ad1ca7f006cf83371f2971db688bb3d6901dc382 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Mon, 2 Mar 2026 08:16:08 +0000 Subject: [PATCH 05/10] Fixed the function to return the sum of 2 parameters properly Corrected the sum function to return the sum of two numbers instead of undefined. --- Sprint-2/2-mandatory-debug/1.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..67403d523 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,22 @@ // Predict and explain first... -// =============> write your prediction here +// =============> write your prediction here: js is a sequential language, as in reads code line by line, so i predict nothing will happen after 'return' is processed and +//some sort of an error message will appear. + +//function sum(a, b) { +// return; +// a + b; +//} + +//console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); + +// =============> write your explanation here: 'undefined' error appeared. Fixed the code by adding the addition on the same line as return. + + +// Finally, correct the code to fix the problem +// =============> write your new code here: 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 -// Finally, correct the code to fix the problem -// =============> write your new code here From f9e4e195e2f561ed3d4dbb7013dd17742702d4b7 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Mon, 2 Mar 2026 14:36:05 +0000 Subject: [PATCH 06/10] Fixed getLastDigit function Updated the getLastDigit function to accept a parameter and removed unused variable. --- Sprint-2/2-mandatory-debug/2.js | 34 +++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..c16d38ab6 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,11 +1,29 @@ // Predict and explain first... -// Predict the output of the following code: -// =============> Write your prediction here +// Predict the output of the following code +// =============> Write your prediction here: i think, the console.log will only show '3' because the paramater hasn't been specified in the function. -const num = 103; +//const num = 103; -function getLastDigit() { +//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)}`); + +// Now run the code and compare the output to your prediction +// =============> write the output here: I've run the code and got '3' in each console.log line. + +// Explain why the output is the way it is +// =============> write your explanation here: It's because there is no parameter in the function to differentiate viarable 103 from 42, 105, 806. + + +// Finally, correct the code to fix the problem +// =============> write your new code here + +function getLastDigit(num) { return num.toString().slice(-1); } @@ -13,12 +31,8 @@ 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 -// Explain why the output is the way it is -// =============> write your explanation here -// Finally, correct the code to fix the problem -// =============> write your new code here + +// it works now, but since cosnt num = 103 is unused, i have removed it. // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem From b7fb44c8693096a36f5ee044d0616679a0c49480 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Mon, 2 Mar 2026 14:56:05 +0000 Subject: [PATCH 07/10] Add calculateBMI function to compute BMI Implement BMI calculation and log result. --- Sprint-2/3-mandatory-implement/1-bmi.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..eb2ca7672 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -14,6 +14,12 @@ // Then when we call this function with the weight and height // It should return their Body Mass Index to 1 decimal place -function calculateBMI(weight, height) { + function calculateBMI(weight, height) { + const bmi = weight / (height * height); + return Number(bmi.toFixed(1)); +} + +console.log(calculateBMI(88, 1.76)); + // return the BMI of someone based off their weight and height -} \ No newline at end of file +} From 9c6d6045d47b102186441514f57be966b1ef243f Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Mon, 2 Mar 2026 15:59:16 +0000 Subject: [PATCH 08/10] Implement toUpperSnakeCase function Add function to convert string to upper snake case --- Sprint-2/3-mandatory-implement/2-cases.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..502ba7a5e 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,10 @@ // 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() + .replaceAll(" ", "_"); +} +console.log(toUpperSnakeCase("hello there")); From 4366cc4fec3956d0f03c06fc0142f8eef4ebe9ae Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Mon, 2 Mar 2026 16:07:27 +0000 Subject: [PATCH 09/10] Added toPounds function for currency conversion to make a reusable block of code. Implemented the toPounds function to convert pence to pounds. --- 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..39f2a96c6 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}`; +} From d46a3dd3d36948ad0bda2b63d5dd367b12ef0e85 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Tue, 3 Mar 2026 08:48:40 +0000 Subject: [PATCH 10/10] Refactor time formatting and add console logs --- Sprint-2/4-mandatory-interpret/time-format.js | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..073e5aa5c 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -1,15 +1,10 @@ -function pad(num) { - return num.toString().padStart(2, "0"); + return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } -function formatTimeDisplay(seconds) { - const remainingSeconds = seconds % 60; - const totalMinutes = (seconds - remainingSeconds) / 60; - const remainingMinutes = totalMinutes % 60; - const totalHours = (totalMinutes - remainingMinutes) / 60; +console.log(formatTimeDisplay(61)); +console.log(formatTimeDisplay(6671)); +console.log(formatTimeDisplay(832)); - return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; -} // You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit // to help you answer these questions @@ -17,18 +12,18 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> write your answer here: pad will be 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: The value is 0. // c) What is the return value of pad is called for the first time? -// =============> write your answer here +// =============> write your answer here: The return value is '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: The value is 1 because 61 % 60 leaves 1 second remaining. // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> write your answer here +// =============> write your answer here: The return value is '01' because return num.toString().padstart(2, '0') formats 1 into '01'.