From 7f1a52d6c27b1013ee698e150d9ad3785580ef88 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Sun, 22 Feb 2026 20:51:47 +0000 Subject: [PATCH 01/14] described how "=" operates, with an example. Corrected the increment operation for the count variable. --- Sprint-1/1-key-exercises/1-count.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..de9653014 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -1,6 +1,7 @@ let count = 0; -count = count + 1; +count = count + 1; +// line 3 is assigning the variable "count" a new value of "count +1", then storing it back into "count". // 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 672d4d6d19b48a79cfa95e2eb79fe92d88f0fa03 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Sun, 22 Feb 2026 21:13:57 +0000 Subject: [PATCH 02/14] Wrote a line of code that extracts initials from each string above and assigned them as "CKJ". --- Sprint-1/1-key-exercises/2-initials.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f617..3e9e5b37c 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,7 @@ 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 = ``; +let initials = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`; // https://www.google.com/search?q=get+first+character+of+string+mdn From deb7eefae794b0692d76d5c5dfd0f8c7b6c02a2e Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Sun, 22 Feb 2026 21:32:02 +0000 Subject: [PATCH 03/14] Extracted directory and extension parts from filePath. --- 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 ab90ebb28..6d2ea8d0f 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -12,12 +12,13 @@ const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; const lastSlashIndex = filePath.lastIndexOf("/"); 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 // Create a variable to store the ext part of the variable -const dir = ; -const ext = ; +const dir = filePath.slice(0,lastSlashIndex); +const ext = filePath.slice(lastDotIndex+1); -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// https://www.google.com/search?q=slice+mdn From eddb7aa03e008bde38b52672293bae1e489e2b47 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Sun, 22 Feb 2026 21:53:57 +0000 Subject: [PATCH 04/14] Explained what num variable would stand for in this example. --- Sprint-1/1-key-exercises/4-random.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..90541e00d 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -2,6 +2,11 @@ const minimum = 1; const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; +//num can be any generated random number between 1 and 100, rounded down. + + + + // 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 From d50f377b453f7536ed0d584949bb25fc7f3cccb6 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Sun, 22 Feb 2026 21:59:00 +0000 Subject: [PATCH 05/14] Erased two lines of code to prevent execution. --- Sprint-1/2-mandatory-errors/0.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..bc9b380c1 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,5 @@ -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 + +//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? + +// I have erased the above two lines, to prevent the computer from running them. From 4d9ad548c5b6cff2b5badca4f8df93377d2ca7be Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Sun, 22 Feb 2026 22:16:18 +0000 Subject: [PATCH 06/14] changed const to let, because one variable can be reassigned and the other cannot. --- Sprint-1/2-mandatory-errors/1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..031839b47 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,4 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; From 8e9765fd6dd5e9d35451fcd48fffeefcfa2f50f2 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Sun, 22 Feb 2026 22:21:37 +0000 Subject: [PATCH 07/14] I have flipped two lines of code around because variable has to be declared first then used. --- Sprint-1/2-mandatory-errors/2.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..cecd34f90 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,8 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? -console.log(`I was born in ${cityOfBirth}`); +//console.log(`I was born in ${cityOfBirth}`); +//const cityOfBirth = "Bolton"; + const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); From ced4d8ccc931570c1862fdc6d11d3b0ea2692eab Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Sun, 22 Feb 2026 22:42:51 +0000 Subject: [PATCH 08/14] added an extra function to turn the card number into a string Changed cardNumber to a string before slicing to get last 4 digits. --- Sprint-1/2-mandatory-errors/3.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..ba6bbc96f 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,13 @@ +//const cardNumber = 4533787178994213; +//const last4Digits = cardNumber.slice(-4); + const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +const last4Digits = String(cardNumber).slice(-4); + +//My prediction was the long card number isn't a string so js will assume it's a variable +//Error given: cardNumber.slice is not a function +//added String function + // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working From eaf851353f7f5bcf68b845dce9146174d78e328c Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Sun, 22 Feb 2026 22:48:04 +0000 Subject: [PATCH 09/14] Rename clock time variables for clarity Updated variable names to follow JavaScript naming conventions. --- Sprint-1/2-mandatory-errors/4.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..38dc0aa81 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,7 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +//const 12HourClockTime = "20:53"; +//const 24hourClockTime = "08:53"; + +const twentyFourHourClockTime = "20:53"; +const twelveHourClockTime = "08:53"; + +//variable names in js cannot start with numbers From fca8c46530431b97d6a0c220fcc105d000c2bc9f Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Mon, 23 Feb 2026 08:22:45 +0000 Subject: [PATCH 10/14] Fix syntax error and added comments to answer the questions. Fixed syntax error by adding a missing comma in replaceAll function calls. --- .../1-percentage-change.js | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..c694b18fe 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -1,8 +1,8 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; -carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +carPrice = Number(carPrice.replaceAll(",","")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",","")); const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; @@ -13,10 +13,27 @@ 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 calls: replaceAll() - used twice, number() - used twice, console.log() - used once. +// carPrice = Number(carPrice.replaceAll("," , "")); +// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," , "")); +// 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? +//There was a syntax error on line five, missing comma. Fixed by adding one. + // 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? + +// It's removing the commas, since javascript will recognise 10,000 as a string not a number. From 33eb3b20b0d054820fb6296f9f94af0937b67349 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Mon, 23 Feb 2026 08:47:03 +0000 Subject: [PATCH 11/14] Add answers to all the questions. --- 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 47d239558..c94205a57 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? +// There are six, all six lines of code use const as a variable declaration. + // b) How many function calls are there? +//There is only one funsction call, console.log(result) + // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +// It represents how many seconds remain, before converting them to minutes first. + // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// it represents the movie length converted to minutes, without the remaining seconds. + // e) What do you think the variable result represents? Can you think of a better name for this variable? +//It represents the film length in a time string format. Better alternative could be formattedDuration, as it is self-explanatory, +//as opposed to generic 'result'. + // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer + +// I have tried values between 0-9, ie all positive/whole numbers, and it works. However there is no input validation, ie negative numbersm, non-integers etc, so it won't work properly there. From ec4e15c7fbbc7798e3f9821522d4b51274bb093a Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Mon, 23 Feb 2026 14:55:22 +0000 Subject: [PATCH 12/14] I have added a brief explanation, after each line of code, to rationalize the reasoning behind the code. --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..228a1f601 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -1,27 +1,27 @@ const penceString = "399p"; - +// 1. const penceString = "399p": initialises a string variable with the value "399p" const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1 ); - +//2. Removes the trailing "p" from the pencestring, leaving 399 as the new value. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +//3. This line ensures there are three characters, at least, by adding "0" to the start if necessary. const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2 ); - +//4. We are extracting the pounds now, ie the first character. const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0"); - +//4. Here, we are extracting the last two digits, ie pence. Padend insures there are two digits and adds a "0" to compensate, if necessary. console.log(`£${pounds}.${pence}`); +//5. Here it should show the final result of £3.99 + // This program takes a string representing a price in pence // The program then builds up a string representing the price in pounds // You need to do a step-by-step breakdown of each line in this program // Try and describe the purpose / rationale behind each step - -// To begin, we can start with -// 1. const penceString = "399p": initialises a string variable with the value "399p" From 48d4945065cc55fbf4ebc3d30523dade1fde6281 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Mon, 23 Feb 2026 15:18:11 +0000 Subject: [PATCH 13/14] Answered both questions. Clarify the effects and return values of alert and prompt functions. --- Sprint-1/4-stretch-explore/chrome.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feaf..6fb250ca9 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -12,7 +12,16 @@ invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? +1. This function displays a pop-up box with Hello world written on it, with on OK button. + Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. What effect does calling the `prompt` function have? + +2. It displays a pop-up box with What's your name written on it and an empty dialog box inside, awaiting my input. +Also, there are two options of OK and Cancel. + What is the return value of `prompt`? + +3. If I enter my name undefined appears, same if i press the cancel button. Fixed this by adding myName at the end. +Now the value when i enter my name shows "my name", if i press cancel it shows "null". From 5d0742b22dd653e3e8d0275bd25409282985f5d1 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Mon, 23 Feb 2026 15:45:59 +0000 Subject: [PATCH 14/14] I have answered five questions asked in this exercise. Added explanations about the console object and its methods. --- Sprint-1/4-stretch-explore/objects.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56..1aeef2306 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -6,11 +6,28 @@ Open the Chrome devtools Console, type in `console.log` and then hit enter What output do you get? +1. I got back, 'ƒ log() { [native code] }' +which is the definition of console function. + Now enter just `console` in the Console, what output do you get back? +2. I got back, console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} +Which is the definition of console as an object with several examples of functions after the object. + Try also entering `typeof console` +3. I've got 'object', it is showing me that console itself is an object. + Answer the following questions: What does `console` store? + +4. The object console stores different functions used for various purposes, such as debugging, showing errors etc. + What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? + +5. console.log allows you access the log property of the console object. ie log is a property stored inside the object. In this case log as a function. + +console.assert - assert is another function stored inside console object, used for checking is a condition is true. + +"." means go inside this property and get the property provided. Perfect example of this is, "person" is an object, "name" is a property and so "." allows me to access the property.