From 398d3ff1a14d336402451c805ddf21975080101c Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Wed, 10 Jun 2026 22:28:53 +0100 Subject: [PATCH 01/12] Add comments to clarify count variable operations Added comments to explain variable declaration and increment operation. --- Sprint-1/1-key-exercises/1-count.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6e..fa9cd03993 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -2,5 +2,9 @@ let count = 0; count = count + 1; +// The assignment operator (=) stores the result of count + 1 in the variable count. i.e. incrementing the count by 1. + // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing + + From 1fd3943907ed2d2b76760e20ba75bebe46412731 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Wed, 10 Jun 2026 22:59:05 +0100 Subject: [PATCH 02/12] Store initials from first characters of names Updated the initials variable to concatenate the first characters of first, middle, and last names. --- Sprint-1/1-key-exercises/2-initials.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f6175..8860864100 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -1,11 +1,16 @@ +// Declare a variable called initials that stores the first character of each string. +// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. + let firstName = "Creola"; let middleName = "Katherine"; let lastName = "Johnson"; -// Declare a variable called initials that stores the first character of each string. -// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. +let initials = firstName[0] + middleName[0] + lastName[0]; + +console.log(initials); + +//I have run this code on chrome console and the answer was CKJ + -let initials = ``; -// https://www.google.com/search?q=get+first+character+of+string+mdn From d04e6d05009175fea1feccf43152f5c7e7920308 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Wed, 10 Jun 2026 23:39:31 +0100 Subject: [PATCH 03/12] Add dir variable and ext variable --- Sprint-1/1-key-exercises/3-paths.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28e..e9eb955ce2 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -15,9 +15,10 @@ const base = filePath.slice(lastSlashIndex + 1); console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable +const dir = filePath.slice(0, lastSlashIndex); + // Create a variable to store the ext part of the variable -const dir = ; -const ext = ; +const ext = base.slice(base.lastIndexOf(".") + 1); -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// https://www.google.com/search?q=slice+mdn From d8c4a2f7d96964914d39537b7947d86a31107e6c Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Thu, 11 Jun 2026 00:11:09 +0100 Subject: [PATCH 04/12] Enhance random.js with explanatory comments Added comments explaining the random number generation logic. --- Sprint-1/1-key-exercises/4-random.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aabb..03d6abfd1c 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -3,7 +3,22 @@ const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; + // In this exercise, you will need to work out what num represents? // Try breaking down the expression and using documentation to explain what it means // It will help to think about the order in which expressions are evaluated // Try logging the value of num and running the program several times to build an idea of what the program is doing + +//Expressions in JS are evaluated from inside out, following the brackets. So (maximum - minimum + 1) would become 100-1+1=100. +//Then we move on to the next outer bracket "Math.random()", which is a function designed to generate random numbers. We multiply that random number +//by 100 and that is our brackets calculated for now. Next in the expression is the function "math.floor" which rounds down numbers to the +//nearest whole number, to which we add the minimum at the end. Which is number 1. + +// I have run this code on my Chrome console multiple times and got a diffrent number each time. + +const minimum = 1; +const maximum = 100; + +const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; + +console.log(num); From 129fd77ccac77221099ae5822560037ef48a9d0c Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Thu, 11 Jun 2026 00:15:05 +0100 Subject: [PATCH 05/12] Comment out instructions in 0.js Comment out instructions to prevent execution. --- Sprint-1/2-mandatory-errors/0.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f7..a5a89d1c5f 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,10 @@ This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +We don't want the computer to run these 2 lines - how can we solve this problem? + +//This is just an instruction for the first activity - but it is just for human consumption +//We don't want the computer to run these 2 lines - how can we solve this problem? + +/* +This is just an instruction for the first activity - but it is just for human consumption +We don't want the computer to run these 2 lines - how can we solve this problem? +*/ From 123760d4f913f7d02a91f1db50f0e6075b0d69eb Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Thu, 11 Jun 2026 00:27:58 +0100 Subject: [PATCH 06/12] Fix age variable reassignment by using 'let' Changed 'const' to 'let' for age variable to allow reassignment. --- Sprint-1/2-mandatory-errors/1.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea76..aa514f25a8 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -2,3 +2,14 @@ const age = 33; age = age + 1; + +/* +Error here is that value for "const" cannot be reassigned. If we wanna see the code work +we must use "let" keyword because the variable can be changed. +*/ + +let age = 33; +age = age + 1; +console.log(age); + +//I have ran this code and got 34 on chrome console From 67a252f1d8f59b96532536a2606a2383d5d26297 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Thu, 11 Jun 2026 00:33:02 +0100 Subject: [PATCH 07/12] Fix variable declaration order in 2.js Declare the variable 'cityOfBirth' before using it in console.log. --- Sprint-1/2-mandatory-errors/2.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831d..0fbdc57f6f 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -3,3 +3,8 @@ console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; + +//We must declare the variable first then use it, because JS reads from top to bottom. + +const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); From b456711bafcc2a171d67bb98aee991a185d2065c Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Thu, 11 Jun 2026 01:07:25 +0100 Subject: [PATCH 08/12] Fix error by converting cardNumber to string Converted cardNumber to string before slicing to extract last four digits. --- Sprint-1/2-mandatory-errors/3.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884db..a79be603b4 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -7,3 +7,19 @@ const last4Digits = cardNumber.slice(-4); // Then run the code and see what error it gives. // Consider: Why does it give this error? Is this what I predicted? If not, what's different? // Then try updating the expression last4Digits is assigned to, in order to get the correct value + + + +/* +The code won't work because the cardNumber is a numeric value and "slice()" works with strings in JS. +I have run the code to get "VM1691:2 Uncaught TypeError: cardNumber.slice is not a function" error. +I guess, JS is trying to find slice function on the cardNumber and since it is not a string it confirms +that it is in fact not a function. +*/ + +const cardNumber = 4533787178994213; +const last4Digits = cardNumber.toString().slice(-4); + +console.log(last4Digits); + +//this code worked because i have converted the cardNumber value to string then sliced the last four digits. From 1f56171f3fffe38cfd1e2ad01bc89918999139ba Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Thu, 11 Jun 2026 01:16:04 +0100 Subject: [PATCH 09/12] Document syntax error in variable naming Added comments explaining the syntax error related to variable naming. --- Sprint-1/2-mandatory-errors/4.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 5f86c730bc..28f5fe93fb 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,9 @@ const 12HourClockTime = "8:53pm"; const 24hourClockTime = "20:53"; + +/* +I have predicted the code won't run due to the fact that "8:53pm" should be "08:53" +Got this error "Uncaught SyntaxError: Invalid or unexpected token", meaning it is a syntax error. +I have searched it up to find that variables can't start with numbers because it makes it easier +for JS to read code by removing a mathematical ambiguity. +*/ From fe54c7f01ca4666b44126847e877b2b66af416c6 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Thu, 11 Jun 2026 11:06:31 +0100 Subject: [PATCH 10/12] Enhance comments for clarity on function calls and errors Added comments to clarify function calls, errors, variable reassignment, and declarations. --- .../1-percentage-change.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e18..211b889298 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -13,10 +13,31 @@ console.log(`The percentage change is ${percentageChange}`); // a) How many function calls are there in this file? Write down all the lines where a function call is made +/* +There are three function call names, but two functions have been made twice inside another, adding up to five function calls being made overall. +1. carPrice.replaceAll(",", "") +2. Number(carPrice.replaceAll(",", "")) this expression contain two, one inside the other +3. priceAfterOneYear.replaceAll(",", "") +4. Number(priceAfterOneYear.replaceAll(",", "")) this expression contains two as well +5. console.log(`The percentage change is ${percentageChange}`) +*/ + // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? +//I have run the code and got a syntax error on line 5, due to two arguments not being seperated by a comma. + // c) Identify all the lines that are variable reassignment statements +//carPrice = Number(carPrice.replaceAll(",", "")); +//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); + // d) Identify all the lines that are variable declarations +//let carPrice = "10,000"; +//let priceAfterOneYear = "8,543"; +//const priceDifference = carPrice - priceAfterOneYear; +//const percentageChange = (priceDifference / carPrice) * 100; + // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? + +//Removing all the comma for calculation then convert the string into a number. From 4c935f3b70f65c8fc30dd84d7fa33025090359d0 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Thu, 11 Jun 2026 11:31:23 +0100 Subject: [PATCH 11/12] Enhance comments for clarity on time format logic Added comments to explain variable declarations, function calls, and expressions related to movie length formatting. --- Sprint-1/3-mandatory-interpret/2-time-format.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d2395587..b381bd4e12 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -13,13 +13,26 @@ console.log(result); // a) How many variable declarations are there in this program? +// Six, every line that starts with "const" keyword. + // b) How many function calls are there? +// One, line 10. + // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +// It calculates how many seconds are left over. + // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// It first removes the leftover seconds from the total movie length, then converts the remaining seconds into minutes. + // e) What do you think the variable result represents? Can you think of a better name for this variable? +// It represents a formatted time string and since it's a movie, i would change "result" variable to "movieDuration". + // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer + +// The code wouldn't work with decimal numbers "because movieLength" is a whole number, also negative numbers won't work +//because movies can't be less than zero. From c5117e1556afb942d040608c301e3d16fb870612 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Thu, 11 Jun 2026 11:56:36 +0100 Subject: [PATCH 12/12] Enhance 3-to-pounds.js with detailed comments Added comments to explain each step of the conversion process from pence to pounds. --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69a..f19c3b2580 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -1,22 +1,35 @@ -const penceString = "399p"; +const penceString = "399p"; // This line shows price in pence with a letter "p" attached at the end. -const penceStringWithoutTrailingP = penceString.substring( - 0, - penceString.length - 1 -); + +const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1); + +// Above line of code removes the "p", using "penceString.substring" function by removing the last character with "-1", +//out of a four digit string "399p". const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); -const pounds = paddedPenceNumberString.substring( - 0, - paddedPenceNumberString.length - 2 -); -const pence = paddedPenceNumberString - .substring(paddedPenceNumberString.length - 2) +// We are using "padstart" method to ensure the string contains three characters at least, +//and if necessary to add "0" to the front. + + +const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2); + +// We are calculating the pounds const variable by taking away the last two digits from "paddedPenceNumberString" const. + +const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2) .padEnd(2, "0"); +//First we extracting the last two digits with "(paddedPenceNumberString.length - 2)", then making ensure the pence part +//has two digits always with "padEnd(2, "0")". Basically calculating the const pence variable. + console.log(`£${pounds}.${pence}`); +//Uses a template literal to combine the pounds and pence values into a currency format and prints the result to the console. + + + + + // This program takes a string representing a price in pence // The program then builds up a string representing the price in pounds