From 22e0557e8c1cadff8df1e9ebd2f2b4c08a938377 Mon Sep 17 00:00:00 2001 From: Carol Date: Tue, 22 Sep 2026 20:40:13 +0100 Subject: [PATCH 1/3] completed Sprint 2 tasks --- Sprint-2/1-key-exercises/1-count.js | 2 ++ Sprint-2/1-key-exercises/2-initials.js | 6 +++++- Sprint-2/1-key-exercises/3-paths.js | 8 ++++++-- Sprint-2/1-key-exercises/4-random.js | 4 ++++ Sprint-2/2-mandatory-errors/0.js | 6 ++++-- Sprint-2/2-mandatory-errors/1.js | 5 +++++ Sprint-2/2-mandatory-errors/2.js | 5 ++++- Sprint-2/2-mandatory-errors/3.js | 5 +++++ Sprint-2/2-mandatory-errors/4.js | 9 +++++++-- .../1-percentage-change.js | 18 +++++++++++++----- .../3-mandatory-interpret/2-time-format.js | 7 ++++++- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 5 +++++ Sprint-2/4-stretch-explore/chrome.md | 2 +- Sprint-2/4-stretch-explore/objects.md | 2 +- 14 files changed, 68 insertions(+), 16 deletions(-) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 117bcb2b6..baa67cfba 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -4,3 +4,5 @@ count = count + 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 + +//Answer: The = means assignment. The value of count is 0 but it increments by 1 \ No newline at end of file diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js index 964c9563c..9e091800e 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -1,10 +1,14 @@ const firstName = "Creola"; const middleName = "Katherine"; const lastName = "Johnson"; +// const initial = "initials"; +// const index = 1; +// console.log('The ${Initial} ${index} is ${firstName.charAt(index)}'); // 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. -const initials = ``; +const initials = firstName[0] + middleName[0] + lastName[0]; +console.log(initials) // https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index ab90ebb28..796e8fbfa 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -17,7 +17,11 @@ 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 = base.slice(base.lastIndexOf(".")); + +console.log(`The dir part of ${filePath} is ${dir}`); +console.log(`The ext part of ${base} is ${ext}`); + // https://www.google.com/search?q=slice+mdn \ No newline at end of file diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 292f83aab..88875d8ea 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -7,3 +7,7 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // 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 + +// Answer: For calculations i utilised BODMAS formula solving numbers in brackets first, multiplication, subtraction and addition +// I used 0.68 for math.floor(random number) + 1 +// Sum = 69 \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index cf6c5039f..5f3f3c523 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/2-mandatory-errors/0.js @@ -1,2 +1,4 @@ -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 commented out the lines. The computer removes commented lines from code compilation \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index 7a43cbea7..d636bc7ea 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -2,3 +2,8 @@ const age = 33; age = age + 1; + +console.log(age) + +// The TypeError: Assignment to constant variable implies we are trying to reassign the variable twice. +// This case, I have used let instead in order to allow the variable to be reused. \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index e09b89831..a57367694 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/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}`); const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); + +// The error is ReferenceError: Cannot access 'cityOfBirth' before initialization +// Answer: I switched the order by declaring the const first before calling /printing \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index ec101884d..4d0bf6de2 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -7,3 +7,8 @@ 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 + +//Prediction was the code would run successfully without error although with the wrong results due to absence of syntax errors in the file +// Error returned: TypeError: cardNumber.slice is not a function +// Lesson learnt here; slice method is only available for strings or arrays not numbers +// So converted the cardNumber into a string first \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 5f86c730b..580680287 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,2 +1,7 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +const twelveHourClockTime = "8:53pm"; +const twentyFourHourClockTime = "20:53"; +console.log(twelveHourClockTime); +console.log(twentyFourHourClockTime); + +// Error - SyntaxError: Invalid or unexpected token +// lesson learnt - variables cannot start with a number diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..3cd429dc3 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -2,7 +2,7 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," , "")); const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; @@ -12,11 +12,19 @@ console.log(`The percentage change is ${percentageChange}`); // Read the code and then answer the questions below // a) How many function calls are there in this file? Write down all the lines where a function call is made - +// 2 +//carPrice = Number(carPrice.replaceAll(",", "")); +//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ",")); // 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? - +//b) error = SyntaxError: missing ) after argument list +// (",", ",")); - added , between quoted values // 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? +// e) cleans the amount format by removing characters such as , and leaving only number \ No newline at end of file diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index 47d239558..c5d68119a 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -12,14 +12,19 @@ console.log(result); // For the piece of code above, read the code and then answer the following questions // a) How many variable declarations are there in this program? +// 6 variables // b) How many function calls are there? - +// 2 // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +// It means 60 % remainder of Movie length // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// totalMinutes is assigned a value of the result from (movieLength - remainingSeconds) / 60; // e) What do you think the variable result represents? Can you think of a better name for this variable? +// I think its the total movie length with a timer. Based on research it appears to be template literal variable as it mixes static text with dynamic data. Sorry I don't fully understand this bit yet // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +//any number greater than zero returns a valid positive hour, minute or seconds result. Changing the length to 0 returns 0:0:0. Any negative length returns negative values diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..06114b75d 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,8 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" +// 2. const penceStringWithoutTrailingP = penceString.substring(0): sets penceStringWithoutTRailingP = 399.0 - penceString -1 = 39 +// 3. const paddedPenceNumberString - ensures the figure is 3 characters to taking us back to 399 +// 4 const pounds - removes 2 characters from the amount = 3 +// 5. const pence - adds the amount by 2 characters taking us back to either 39 or 99 +// 6. console displays the figures in pounds and pence = 3.99 \ No newline at end of file diff --git a/Sprint-2/4-stretch-explore/chrome.md b/Sprint-2/4-stretch-explore/chrome.md index 962580b82..7a24c0bfa 100644 --- a/Sprint-2/4-stretch-explore/chrome.md +++ b/Sprint-2/4-stretch-explore/chrome.md @@ -12,4 +12,4 @@ What effect does calling the `alert` function have? 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? -What is the return value of `prompt`? +What is the return value of `prompt`?. diff --git a/Sprint-2/4-stretch-explore/objects.md b/Sprint-2/4-stretch-explore/objects.md index 0216dee56..bebb00f08 100644 --- a/Sprint-2/4-stretch-explore/objects.md +++ b/Sprint-2/4-stretch-explore/objects.md @@ -13,4 +13,4 @@ Try also entering `typeof console` Answer the following questions: What does `console` store? -What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?. From 95ef2103f7669aae05fb9e700320d989993b1ea8 Mon Sep 17 00:00:00 2001 From: Carol Date: Thu, 24 Sep 2026 09:41:33 +0100 Subject: [PATCH 2/3] corrected issues identified by the reviewer --- Sprint-2/1-key-exercises/2-initials.js | 5 +---- Sprint-2/1-key-exercises/4-random.js | 9 ++++++++- Sprint-2/2-mandatory-errors/1.js | 6 +++--- Sprint-2/2-mandatory-errors/3.js | 5 +++-- .../3-mandatory-interpret/1-percentage-change.js | 12 +++++++----- Sprint-2/3-mandatory-interpret/2-time-format.js | 5 ++++- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 8 +++++--- 7 files changed, 31 insertions(+), 19 deletions(-) diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js index 9e091800e..3d28a33a4 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -1,11 +1,8 @@ const firstName = "Creola"; const middleName = "Katherine"; const lastName = "Johnson"; -// const initial = "initials"; -// const index = 1; -// console.log('The ${Initial} ${index} is ${firstName.charAt(index)}'); -// 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. const initials = firstName[0] + middleName[0] + lastName[0]; diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 88875d8ea..2ee7e8964 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -2,6 +2,8 @@ const minimum = 1; const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; +// (0.68 * 100 ) + 1 +console.log(num) // 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 @@ -10,4 +12,9 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // Answer: For calculations i utilised BODMAS formula solving numbers in brackets first, multiplication, subtraction and addition // I used 0.68 for math.floor(random number) + 1 -// Sum = 69 \ No newline at end of file +// Sum = 69 +// 1.num represents a number which is an Integer that is greater or equal to 1 +// 2.start by (maximum-minimum +1) which the output is 100 +// 3.math.random()*100 returns random number between 0 and 100. Any random number less that 1 can be selected then multiplied by 100 +// 4.math.floor() gives out the largest integer which is less than or equal to the given number which is a decimal +// The output is displayed in console log \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index d636bc7ea..d7b2a79f1 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -1,9 +1,9 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; -console.log(age) +console.log(age); // The TypeError: Assignment to constant variable implies we are trying to reassign the variable twice. -// This case, I have used let instead in order to allow the variable to be reused. \ No newline at end of file +// This case, I have used let instead in order to allow the variable to be reused. diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index 4d0bf6de2..aca4c6426 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,5 +1,6 @@ -const cardNumber = 4533787178994213; +const cardNumber = "4533787178994213"; const last4Digits = cardNumber.slice(-4); +console.log(last4Digits); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -11,4 +12,4 @@ const last4Digits = cardNumber.slice(-4); //Prediction was the code would run successfully without error although with the wrong results due to absence of syntax errors in the file // Error returned: TypeError: cardNumber.slice is not a function // Lesson learnt here; slice method is only available for strings or arrays not numbers -// So converted the cardNumber into a string first \ No newline at end of file +// So converted the cardNumber into a string first diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index 3cd429dc3..f63ceffd5 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -2,7 +2,7 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," , "")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; @@ -12,12 +12,14 @@ console.log(`The percentage change is ${percentageChange}`); // Read the code and then answer the questions below // a) How many function calls are there in this file? Write down all the lines where a function call is made -// 2 -//carPrice = Number(carPrice.replaceAll(",", "")); -//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ",")); +// 5 +// * number() and .replaceAll() in line 4 +// * number() and .replaceAll()in line 4 +// console.log() // 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? //b) error = SyntaxError: missing ) after argument list // (",", ",")); - added , between quoted values +// The error was coming from line 5 due to a missing comma in the replaceAll() method // c) Identify all the lines that are variable reassignment statements //carPrice = Number(carPrice.replaceAll(",", "")); //priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ",")); @@ -27,4 +29,4 @@ console.log(`The percentage change is ${percentageChange}`); //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? -// e) cleans the amount format by removing characters such as , and leaving only number \ No newline at end of file +// e) cleans the amount format by removing characters such as , and leaving only number diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index c5d68119a..6db28d89c 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -15,16 +15,19 @@ console.log(result); // 6 variables // b) How many function calls are there? -// 2 +// 1 (console.log()) // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators // It means 60 % remainder of Movie length +// 24 seconds // d) Interpret line 4, what does the expression assigned to totalMinutes mean? // totalMinutes is assigned a value of the result from (movieLength - remainingSeconds) / 60; +//it means changing the value that was in second into minute by dividing it 60 - making it a whole number // e) What do you think the variable result represents? Can you think of a better name for this variable? // I think its the total movie length with a timer. Based on research it appears to be template literal variable as it mixes static text with dynamic data. Sorry I don't fully understand this bit yet +// It represents the MovieDuration // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer //any number greater than zero returns a valid positive hour, minute or seconds result. Changing the length to 0 returns 0:0:0. Any negative length returns negative values diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 06114b75d..a1a95498f 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -2,13 +2,13 @@ const penceString = "399p"; const penceStringWithoutTrailingP = penceString.substring( 0, - penceString.length - 1 + penceString.length - 1, ); const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); const pounds = paddedPenceNumberString.substring( 0, - paddedPenceNumberString.length - 2 + paddedPenceNumberString.length - 2, ); const pence = paddedPenceNumberString @@ -26,7 +26,9 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" // 2. const penceStringWithoutTrailingP = penceString.substring(0): sets penceStringWithoutTRailingP = 399.0 - penceString -1 = 39 +// 2. P will be dropped // 3. const paddedPenceNumberString - ensures the figure is 3 characters to taking us back to 399 // 4 const pounds - removes 2 characters from the amount = 3 // 5. const pence - adds the amount by 2 characters taking us back to either 39 or 99 -// 6. console displays the figures in pounds and pence = 3.99 \ No newline at end of file +// 5. const pence is initialised in 2 methods 1)extracts the string from index 2)adds 0 hence = 99 +// 6. console displays the figures in pounds and pence = 3.99 From b6395cf3a471b6a79d8601ca1d62a490d413804a Mon Sep 17 00:00:00 2001 From: Carol Date: Thu, 24 Sep 2026 20:24:35 +0100 Subject: [PATCH 3/3] updated files as per review instructions --- Sprint-2/1-key-exercises/1-count.js | 2 +- Sprint-2/1-key-exercises/2-initials.js | 3 +-- Sprint-2/1-key-exercises/3-paths.js | 3 +-- Sprint-2/1-key-exercises/4-random.js | 7 ++++--- Sprint-2/2-mandatory-errors/0.js | 2 +- Sprint-2/2-mandatory-errors/2.js | 2 +- Sprint-2/2-mandatory-errors/3.js | 6 +++--- Sprint-2/3-mandatory-interpret/1-percentage-change.js | 4 ++-- Sprint-2/3-mandatory-interpret/2-time-format.js | 3 +-- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 4 +--- 10 files changed, 16 insertions(+), 20 deletions(-) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index baa67cfba..66ecf3eea 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -5,4 +5,4 @@ count = count + 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 -//Answer: The = means assignment. The value of count is 0 but it increments by 1 \ No newline at end of file +//Answer: The = means assignment. The value of count is 0 but it increments by 1 diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js index 3d28a33a4..97aef4211 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -2,10 +2,9 @@ const firstName = "Creola"; const middleName = "Katherine"; const lastName = "Johnson"; - // This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. const initials = firstName[0] + middleName[0] + lastName[0]; -console.log(initials) +console.log(initials); // https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index 796e8fbfa..d4d6521c6 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -23,5 +23,4 @@ const ext = base.slice(base.lastIndexOf(".")); console.log(`The dir part of ${filePath} is ${dir}`); console.log(`The ext part of ${base} is ${ext}`); - -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// https://www.google.com/search?q=slice+mdn diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 2ee7e8964..3e5ff287d 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -3,7 +3,7 @@ const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // (0.68 * 100 ) + 1 -console.log(num) +console.log(num); // 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 @@ -13,8 +13,9 @@ console.log(num) // Answer: For calculations i utilised BODMAS formula solving numbers in brackets first, multiplication, subtraction and addition // I used 0.68 for math.floor(random number) + 1 // Sum = 69 -// 1.num represents a number which is an Integer that is greater or equal to 1 +// 1.num is a random whole number from 1 to 100. // 2.start by (maximum-minimum +1) which the output is 100 // 3.math.random()*100 returns random number between 0 and 100. Any random number less that 1 can be selected then multiplied by 100 // 4.math.floor() gives out the largest integer which is less than or equal to the given number which is a decimal -// The output is displayed in console log \ No newline at end of file +// The output is displayed in console log +// 5. + minimum adds 1. So the range 0 to 99 becomes 1 to 100. diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index 5f3f3c523..9c489ef6d 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/2-mandatory-errors/0.js @@ -1,4 +1,4 @@ // 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 commented out the lines. The computer removes commented lines from code compilation \ No newline at end of file +// I have commented out the lines. The computer removes commented lines from code compilation diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index a57367694..1ae761282 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -5,4 +5,4 @@ const cityOfBirth = "Bolton"; console.log(`I was born in ${cityOfBirth}`); // The error is ReferenceError: Cannot access 'cityOfBirth' before initialization -// Answer: I switched the order by declaring the const first before calling /printing \ No newline at end of file +// Answer: I switched the order by declaring the const first before calling /printing diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index aca4c6426..9529c9035 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,5 +1,5 @@ -const cardNumber = "4533787178994213"; -const last4Digits = cardNumber.slice(-4); +const cardNumber = 4533787178994213; +const last4Digits = String(cardNumber).slice(-4); console.log(last4Digits); // The last4Digits variable should store the last 4 digits of cardNumber @@ -12,4 +12,4 @@ console.log(last4Digits); //Prediction was the code would run successfully without error although with the wrong results due to absence of syntax errors in the file // Error returned: TypeError: cardNumber.slice is not a function // Lesson learnt here; slice method is only available for strings or arrays not numbers -// So converted the cardNumber into a string first +// I used String() on line 2 to turn the number into a string diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index f63ceffd5..455f85e36 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -14,8 +14,8 @@ 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 // 5 // * number() and .replaceAll() in line 4 -// * number() and .replaceAll()in line 4 -// console.log() +// * number() and .replaceAll()in line 5 +// console.log() is on line 10 // 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? //b) error = SyntaxError: missing ) after argument list // (",", ",")); - added , between quoted values diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index 6db28d89c..6a42a18c9 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -18,7 +18,6 @@ console.log(result); // 1 (console.log()) // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators -// It means 60 % remainder of Movie length // 24 seconds // d) Interpret line 4, what does the expression assigned to totalMinutes mean? @@ -27,7 +26,7 @@ console.log(result); // e) What do you think the variable result represents? Can you think of a better name for this variable? // I think its the total movie length with a timer. Based on research it appears to be template literal variable as it mixes static text with dynamic data. Sorry I don't fully understand this bit yet -// It represents the MovieDuration +// It represents the movieDuration // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer //any number greater than zero returns a valid positive hour, minute or seconds result. Changing the length to 0 returns 0:0:0. Any negative length returns negative values diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index a1a95498f..e01985b27 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -25,10 +25,8 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" -// 2. const penceStringWithoutTrailingP = penceString.substring(0): sets penceStringWithoutTRailingP = 399.0 - penceString -1 = 39 // 2. P will be dropped // 3. const paddedPenceNumberString - ensures the figure is 3 characters to taking us back to 399 // 4 const pounds - removes 2 characters from the amount = 3 -// 5. const pence - adds the amount by 2 characters taking us back to either 39 or 99 -// 5. const pence is initialised in 2 methods 1)extracts the string from index 2)adds 0 hence = 99 +// 5. substring(paddedPenceNumberString.length - 2) takes the last 2 characters of 399 which is 99. padEnd(2, "0") adds zeros for strings shorter than 2 characters. In this case, 99 is already 2 characters so nothing is added. // 6. console displays the figures in pounds and pence = 3.99