From 1eb4e07fe265f7ef02dd224503f81371dceebece Mon Sep 17 00:00:00 2001 From: Abayie Date: Sat, 21 Jun 2025 07:26:24 +0100 Subject: [PATCH 01/23] prep --- prep/example.js | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 prep/example.js diff --git a/prep/example.js b/prep/example.js new file mode 100644 index 000000000..f3bfd7449 --- /dev/null +++ b/prep/example.js @@ -0,0 +1,5 @@ +// function decimalTopercent(num){ +// let percent = num * 100; +// return percent +// } +// console.log(decimalTopercent(0.5) + "%"); From bc143cef416bae1b5539f4a7f7d31147aefb236f Mon Sep 17 00:00:00 2001 From: Abayie Date: Sat, 21 Jun 2025 07:41:16 +0100 Subject: [PATCH 02/23] prep-files --- prep/example.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/prep/example.js b/prep/example.js index f3bfd7449..eddee5ebe 100644 --- a/prep/example.js +++ b/prep/example.js @@ -3,3 +3,12 @@ // return percent // } // console.log(decimalTopercent(0.5) + "%"); + +const decimalNumber = 0.5; + +function convertToPercentage() { + const percentage = `${decimalNumber * 100}%`; +} + +convertToPercentage(0.5); +console.log(percentage); \ No newline at end of file From 5cb7a479613203db1bbf200eed04aed40653d8b4 Mon Sep 17 00:00:00 2001 From: Abayie Date: Sat, 21 Jun 2025 08:02:03 +0100 Subject: [PATCH 03/23] functions --- prep/example.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/prep/example.js b/prep/example.js index eddee5ebe..5fb4293a2 100644 --- a/prep/example.js +++ b/prep/example.js @@ -4,11 +4,12 @@ // } // console.log(decimalTopercent(0.5) + "%"); -const decimalNumber = 0.5; - -function convertToPercentage() { +function convertToPercentage(decimalNumber) { const percentage = `${decimalNumber * 100}%`; + return percentage; } -convertToPercentage(0.5); -console.log(percentage); \ No newline at end of file +const result = convertToPercentage(0.5); +const result1 = convertToPercentage(0.231); +console.log(result); +console.log(result1); From b9497924e1f88c1fc40dd6361924886cdefa14d0 Mon Sep 17 00:00:00 2001 From: Abayie Date: Sun, 22 Jun 2025 10:22:26 +0100 Subject: [PATCH 04/23] 1-count.js --- Sprint-1/1-key-exercises/1-count.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..c4bcedeca 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -2,5 +2,8 @@ let count = 0; 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 +//Line 3 is reassigning variable count with a new value, in this case we're saying add 1 to whatever we already have in count, and so by using the console.log before and after the reassignment the we can tell new value of count is 1 \ No newline at end of file From 198f1ae6d5d350bd91b7aac5ae62a03dfe5b0ae0 Mon Sep 17 00:00:00 2001 From: Abayie Date: Sun, 22 Jun 2025 11:55:26 +0100 Subject: [PATCH 05/23] 2-initials.js --- Sprint-1/1-key-exercises/1-count.js | 5 ++++- Sprint-1/1-key-exercises/2-initials.js | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index c4bcedeca..d1d34826d 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -6,4 +6,7 @@ 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 -//Line 3 is reassigning variable count with a new value, in this case we're saying add 1 to whatever we already have in count, and so by using the console.log before and after the reassignment the we can tell new value of count is 1 \ No newline at end of file + +/*Line 3 is reassigning variable count with a new value, in this case we're saying add 1 to whatever we already have in count, +and so by using the console.log before and after the reassignment the we can tell new value of count is 1 +*/ \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f617..f1fad77a4 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,10 @@ 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.slice(0,1)}${middleName.slice(0,1)}${lastName.slice(0,1)}`; +let initials = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`; // https://www.google.com/search?q=get+first+character+of+string+mdn +console.log(initials); From 5357eaba6a58c32c6201259058b7e1ff7785fb25 Mon Sep 17 00:00:00 2001 From: Abayie Date: Sun, 22 Jun 2025 13:15:47 +0100 Subject: [PATCH 06/23] 2-initials --- Sprint-1/1-key-exercises/2-initials.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index f1fad77a4..48721e56a 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -6,9 +6,27 @@ let 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. -// let initials = `${firstName.slice(0,1)}${middleName.slice(0,1)}${lastName.slice(0,1)}`; -let initials = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`; +// let initials = `${firstName.slice(0,1)}${middleName.slice(0,1)}${lastName.slice(0,1)}`; using slice on template literals + +//let initials = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`; using charAt on template literals + +//let initials = (firstName[0] || '') + (middleName[0] || '') + (lastName[0] || ''); using concatenation + +// let initials = `${firstName[0] || ''}${middleName[0] || ''}${lastName[0] || ''}` //template literals + +//let initials = [firstName, middleName, lastName].map(name => name.slice(0,1)).join('') + +let initials = [firstName, middleName, lastName].map(name => name.charAt(0)).join('') + +/* +There are more efficient ways of implementing the solution, however these concepts haven't been covered yet +In these scenarios the slice and charAt have been implemented through a map + +let initials = [firstName, middleName, lastName].map(name => name.slice(0,1)).join('') +let initials = [firstName, middleName, lastName].map(name => name.charAt(0)).join('') + +*/ // https://www.google.com/search?q=get+first+character+of+string+mdn -console.log(initials); +console.log(initials); // display the output of initials to verify if successfuly executed From 25632b9386ad3b048017d391af25421795b0f654 Mon Sep 17 00:00:00 2001 From: Abayie Date: Sun, 22 Jun 2025 14:19:02 +0100 Subject: [PATCH 07/23] 3-paths.js --- Sprint-1/1-key-exercises/2-initials.js | 7 ++++++- Sprint-1/1-key-exercises/3-paths.js | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 48721e56a..7e241ab87 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -20,11 +20,16 @@ let initials = [firstName, middleName, lastName].map(name => name.charAt(0)).joi /* There are more efficient ways of implementing the solution, however these concepts haven't been covered yet -In these scenarios the slice and charAt have been implemented through a map +In these scenarios the slice and charAt have been implemented through an array and map let initials = [firstName, middleName, lastName].map(name => name.slice(0,1)).join('') let initials = [firstName, middleName, lastName].map(name => name.charAt(0)).join('') + +Direct use of `charAt`, `slice`, or indexing is simple and readable for a fixed number of names but becomes repetitive and less scalable. +Using an array with `map` is concise, scalable, and handles missing names well, making it best for variable-length inputs. +Template literals or concatenation with `||` are concise and handle missing names, but are still repetitive for many name parts. +For flexibility, the array + map approach is generally preferred. */ // https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28..7314d71b1 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -15,9 +15,20 @@ 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); // Extract the directory part (everything before the last slash) + + + + // Create a variable to store the ext part of the variable +const lastDotIndex = base.lastIndexOf("."); // Find the index of the last dot in the base to get the extension +const ext = lastDotIndex !== -1 ? base.slice(lastDotIndex) : ""; // Extract the extension (including the dot), or empty string if none + + + + -const dir = ; -const ext = ; +console.log(`The dir part of ${filePath} is ${dir}`); +console.log(`The ext part of ${filePath} is ${ext}`); // https://www.google.com/search?q=slice+mdn \ No newline at end of file From 65e92859aeb39d525dd92c47e66d6dee2420d84a Mon Sep 17 00:00:00 2001 From: Abayie Date: Sun, 22 Jun 2025 14:24:57 +0100 Subject: [PATCH 08/23] 4-random.js --- Sprint-1/1-key-exercises/4-random.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..ad512fada 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -1,3 +1,14 @@ +/** + * Generates a random integer between the specified minimum and maximum values, inclusive. + * + * The expression `Math.floor(Math.random() * (maximum - minimum + 1)) + minimum` works as follows: + * 1. `Math.random()` generates a floating-point number in the range [0, 1). + * 2. Multiplying by `(maximum - minimum + 1)` scales this to the range [0, maximum - minimum + 1). + * 3. `Math.floor()` rounds the result down to the nearest integer, giving a value in [0, maximum - minimum]. + * 4. Adding `minimum` shifts the range to [minimum, maximum]. + * + * As a result, `num` will be a random integer between `minimum` and `maximum`, inclusive. + */ const minimum = 1; const maximum = 100; @@ -7,3 +18,5 @@ 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 + +console.log(num); From 34cf88c7d7b509ad8f74bbdd6e94cd258adbe3bf Mon Sep 17 00:00:00 2001 From: Abayie Date: Sun, 22 Jun 2025 14:37:09 +0100 Subject: [PATCH 09/23] 1.js --- Sprint-1/2-mandatory-errors/0.js | 5 +++-- Sprint-1/2-mandatory-errors/1.js | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..908a9d437 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,3 @@ -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? +*/ \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..6c2584208 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,11 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +//const age = 33; // redeclaring with a let or var solves this error +/* variables declared with `const` in JavaScript cannot be reassigned. +However, if the `const` variable is an object or array, +its contents can still be changed (the reference is immutable, not the value). +*/ +let age = 33; age = age + 1; + +console.log(age); From eff1a8f7e9f03792d7acc7c0650ea1af90074b80 Mon Sep 17 00:00:00 2001 From: Abayie Date: Sun, 22 Jun 2025 14:42:29 +0100 Subject: [PATCH 10/23] 2.js --- Sprint-1/2-mandatory-errors/2.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..88eef170d 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,13 @@ // 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}`); +/* +This happens because in JavaScript, variables declared with `let` or `const` are not accessible before their declaration +due to a behavior called the **temporal dead zone**. +If you try to use such a variable before it’s initialized, you get a `ReferenceError`. +To avoid this, always declare and assign your variables before using them. + +*/ const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); + From 6123bb4dfdf5d1cbc79e6dcd917aab26a78c9e2f Mon Sep 17 00:00:00 2001 From: Abayie Date: Sun, 22 Jun 2025 14:51:27 +0100 Subject: [PATCH 11/23] 3.js --- Sprint-1/2-mandatory-errors/3.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..341560d2d 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,5 @@ -const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +// const cardNumber = 4533787178994213; +// const last4Digits = cardNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,3 +7,21 @@ 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 + + + +/* This code throws an error because `cardNumber` is a **number**, and numbers do not have a `.slice()` method—`.slice()` is a method for strings and arrays. + +**How to fix:** +Convert `cardNumber` to a string before using `.slice()`: + +````javascript +const cardNumber = 4533787178994213; +const last4Digits = cardNumber.toString().slice(-4); +```` + +Now, `last4Digits` will correctly contain the last 4 digits as a string.*/ + +const cardNumber = 4533787178994213; +const last4Digits = cardNumber.toString().slice(-4); +console.log(last4Digits); \ No newline at end of file From e8b8bb9286faeb8cdea2b8d8ddda1d4c8a631144 Mon Sep 17 00:00:00 2001 From: Abayie Date: Sun, 22 Jun 2025 14:55:02 +0100 Subject: [PATCH 12/23] 4.js --- Sprint-1/2-mandatory-errors/4.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..a4a10c1f4 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,6 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +// const 12HourClockTime = "20:53"; +// const 24hourClockTime = "08:53"; + +// variables in js can't begin with numbers +const twelveHourClockTime = "20:53"; +const twenty24hourClockTime = "08:53"; \ No newline at end of file From 49bec3d9537a682fa29ef9350f7c9814d6b470c4 Mon Sep 17 00:00:00 2001 From: Abayie Date: Sat, 28 Jun 2025 23:55:11 +0100 Subject: [PATCH 13/23] 3-to-pounds.js --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..420c25b6b 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,27 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" + +/* + +1. const penceString = "399p"; +Initializes a string variable with the value "399p", representing a price in pence with a trailing "p". + +2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1); +Removes the trailing "p" character from the string, leaving only the numeric part (e.g., "399"). + +3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +Pads the numeric string on the left with zeros so it is at least 3 characters long (e.g., "399" stays "399", but "9" would become "009"). This ensures consistent formatting for the next steps. + +4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2); +Extracts all but the last two characters to represent the pounds part (e.g., from "399", it takes "3"). + +5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); +Extracts the last two characters for the pence part (e.g., from "399", it takes "99"). If there are fewer than two characters, it pads the result on the right with zeros. + +c6. onsole.log(£${pounds}.${pence}); +Outputs the formatted price in pounds and pence (e.g., "£3.99"). + + +*/ + From fea47a8c4449e50844d6e6bd392f5e7a5f2272a2 Mon Sep 17 00:00:00 2001 From: Abayie Date: Sun, 29 Jun 2025 00:01:52 +0100 Subject: [PATCH 14/23] 2-time-format.js --- .../3-mandatory-interpret/2-time-format.js | 45 +++++++++++++++++++ 1 file changed, 45 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..e505e832c 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -23,3 +23,48 @@ console.log(result); // e) What do you think the variable result represents? Can you think of a better name for this variable? // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer + + +/* SOLUTION + +a) **How many variable declarations are there in this program?** +There are **5** variable declarations: `movieLength`, `remainingSeconds`, `totalMinutes`, `remainingMinutes`, `totalHours`, and `result`. + +b) **How many function calls are there?** +- The template literal uses `${...}` expressions, but these are not function calls. +- The only function call is `console.log(result);`. +So, there is **1** function call. + +c) **Using documentation, explain what the expression `movieLength % 60` represents** +The `%` operator returns the remainder after dividing `movieLength` by `60`. In this context, it gives the number of seconds left after converting as many full minutes +as possible from the total seconds. + +d) **Interpret line 4, what does the expression assigned to `totalMinutes` mean?** +`(movieLength - remainingSeconds) / 60` subtracts the leftover seconds from the total, then divides by 60 to get the total number of complete minutes in the movie. + +e) **What do you think the variable `result` represents? Can you think of a better name for this variable?** +`result` represents the movie length formatted as `hours:minutes:seconds`. A better name could be `formattedTime` or `movieLengthHMS`. + +f) **Try experimenting with different values of `movieLength`. Will this code work for all values of `movieLength`? Explain your answer** +The code works for positive integer values of `movieLength`. However, for values less than 60, `totalHours` and `remainingMinutes` will be `0`, which is correct. +For negative or non-integer values, the output may not make sense. Also, the output does not pad single-digit minutes or seconds with a leading zero (e.g., `1:2:3` instead of `01:02:03`). + + + + + + + + + + + + + + + + + + + +*/ \ No newline at end of file From 5b21ac9479f1672e41a5d4eae4de87b8c6367536 Mon Sep 17 00:00:00 2001 From: Abayie Date: Sun, 29 Jun 2025 00:08:34 +0100 Subject: [PATCH 15/23] 1-percentage-change.js --- .../1-percentage-change.js | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..5904e90a6 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/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; @@ -20,3 +20,57 @@ console.log(`The percentage change is ${percentageChange}`); // d) Identify all the lines that are variable declarations // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? + + +/* SOLUTION + + +a) **How many function calls are there in this file? Write down all the lines where a function call is made** +There are **5 function calls**: +1. `carPrice.replaceAll(",", "")` +2. `Number(carPrice.replaceAll(",", ""))` +3. `priceAfterOneYear.replaceAll("," "")` (should be `replaceAll(",", "")`) +4. `Number(priceAfterOneYear.replaceAll("," ""))` (should be `replaceAll(",", "")`) +5. `console.log(...)` + +**Lines with function calls:** +- `carPrice = Number(carPrice.replaceAll(",", ""));` +- `priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));` +- `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?** +The error is on this line: +```javascript +priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +``` +There is a syntax error: `replaceAll("," "")` is missing a comma between the arguments. +**Fix:** +```javascript +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); +``` + +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 removes all commas from the `carPrice` string (e.g., turns `"10,000"` into `"10000"`), then converts the result to a number (`10000`). +This allows for mathematical operations on the price. + + + + + + + + + + + +*/ From ab08eb8094c6fbb027e6067eaa55d54dd670fd72 Mon Sep 17 00:00:00 2001 From: Abayie Date: Thu, 17 Jul 2025 02:04:53 +0100 Subject: [PATCH 16/23] clean --- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index 5904e90a6..9486e68f6 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -65,12 +65,4 @@ This allows for mathematical operations on the price. - - - - - - - - */ From bb12ae4fc7551258ef46b82cc68fc7ebb42ea8fa Mon Sep 17 00:00:00 2001 From: Abayie Date: Thu, 17 Jul 2025 02:07:40 +0100 Subject: [PATCH 17/23] prettier --- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 3 +-- Sprint-1/3-mandatory-interpret/2-time-format.js | 3 +-- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 1 - 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index 9486e68f6..0a5457e9d 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/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; @@ -21,7 +21,6 @@ console.log(`The percentage change is ${percentageChange}`); // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? - /* SOLUTION diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index e505e832c..fc2fe0520 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -24,7 +24,6 @@ console.log(result); // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer - /* SOLUTION a) **How many variable declarations are there in this program?** @@ -67,4 +66,4 @@ For negative or non-integer values, the output may not make sense. Also, the out -*/ \ No newline at end of file +*/ diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 420c25b6b..5d84ea103 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -48,4 +48,3 @@ Outputs the formatted price in pounds and pence (e.g., "£3.99"). */ - From 868b2f3088af8505c2a974e87f8f762664fa1b4c Mon Sep 17 00:00:00 2001 From: Abayie Date: Thu, 17 Jul 2025 02:08:41 +0100 Subject: [PATCH 18/23] prettier --- Sprint-1/1-key-exercises/1-count.js | 4 +--- Sprint-1/1-key-exercises/2-initials.js | 5 +++-- Sprint-1/1-key-exercises/3-paths.js | 9 +-------- Sprint-1/2-mandatory-errors/0.js | 2 +- Sprint-1/2-mandatory-errors/2.js | 1 - Sprint-1/2-mandatory-errors/3.js | 4 +--- Sprint-1/2-mandatory-errors/4.js | 2 +- 7 files changed, 8 insertions(+), 19 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index d1d34826d..ba7f8c4c8 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -2,11 +2,9 @@ let count = 0; 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 /*Line 3 is reassigning variable count with a new value, in this case we're saying add 1 to whatever we already have in count, and so by using the console.log before and after the reassignment the we can tell new value of count is 1 -*/ \ No newline at end of file +*/ diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 7e241ab87..84f39df4f 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,6 @@ 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.slice(0,1)}${middleName.slice(0,1)}${lastName.slice(0,1)}`; using slice on template literals //let initials = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`; using charAt on template literals @@ -16,7 +15,9 @@ let lastName = "Johnson"; //let initials = [firstName, middleName, lastName].map(name => name.slice(0,1)).join('') -let initials = [firstName, middleName, lastName].map(name => name.charAt(0)).join('') +let initials = [firstName, middleName, lastName] + .map((name) => name.charAt(0)) + .join(""); /* There are more efficient ways of implementing the solution, however these concepts haven't been covered yet diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index 7314d71b1..3fe69a5f8 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,18 +17,11 @@ 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); // Extract the directory part (everything before the last slash) - - - // Create a variable to store the ext part of the variable const lastDotIndex = base.lastIndexOf("."); // Find the index of the last dot in the base to get the extension const ext = lastDotIndex !== -1 ? base.slice(lastDotIndex) : ""; // Extract the extension (including the dot), or empty string if none - - - - console.log(`The dir part of ${filePath} is ${dir}`); console.log(`The ext part of ${filePath} 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-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index 908a9d437..95172e41e 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,3 +1,3 @@ /*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 +*/ diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index 88eef170d..ffaf92561 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -10,4 +10,3 @@ To avoid this, always declare and assign your variables before using them. */ const cityOfBirth = "Bolton"; console.log(`I was born in ${cityOfBirth}`); - diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index 341560d2d..ad61366f6 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -8,8 +8,6 @@ // 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 - - /* This code throws an error because `cardNumber` is a **number**, and numbers do not have a `.slice()` method—`.slice()` is a method for strings and arrays. **How to fix:** @@ -24,4 +22,4 @@ Now, `last4Digits` will correctly contain the last 4 digits as a string.*/ const cardNumber = 4533787178994213; const last4Digits = cardNumber.toString().slice(-4); -console.log(last4Digits); \ No newline at end of file +console.log(last4Digits); diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index a4a10c1f4..1e35ff91b 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -3,4 +3,4 @@ // variables in js can't begin with numbers const twelveHourClockTime = "20:53"; -const twenty24hourClockTime = "08:53"; \ No newline at end of file +const twenty24hourClockTime = "08:53"; From 5c9e5f78243565eb52cc2afdd7aa3def9524a6dc Mon Sep 17 00:00:00 2001 From: Abayie Date: Thu, 17 Jul 2025 02:27:51 +0100 Subject: [PATCH 19/23] clean --- .../3-mandatory-interpret/1-percentage-change.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index 0a5457e9d..3e04bea95 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -9,18 +9,6 @@ const percentageChange = (priceDifference / carPrice) * 100; 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 - -// 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? - -// c) Identify all the lines that are variable reassignment statements - -// d) Identify all the lines that are variable declarations - -// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? - /* SOLUTION From 9cc908bd2d80fdfd048ab30e3e46b13424decfad Mon Sep 17 00:00:00 2001 From: Abayie Date: Thu, 17 Jul 2025 02:29:20 +0100 Subject: [PATCH 20/23] clean --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 5d84ea103..e3608a280 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -28,9 +28,6 @@ console.log(`£${pounds}.${pence}`); /* -1. const penceString = "399p"; -Initializes a string variable with the value "399p", representing a price in pence with a trailing "p". - 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1); Removes the trailing "p" character from the string, leaving only the numeric part (e.g., "399"). From f7704ee2eabe65f378d7b44a2a6ad890873d20bf Mon Sep 17 00:00:00 2001 From: Jonathan Boahene Date: Fri, 18 Jul 2025 07:26:27 +0100 Subject: [PATCH 21/23] Update 2-time-format.js --- Sprint-1/3-mandatory-interpret/2-time-format.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index fc2fe0520..6e7bfe76e 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -27,7 +27,7 @@ console.log(result); /* SOLUTION a) **How many variable declarations are there in this program?** -There are **5** variable declarations: `movieLength`, `remainingSeconds`, `totalMinutes`, `remainingMinutes`, `totalHours`, and `result`. +There are **6** variable declarations: `movieLength`, `remainingSeconds`, `totalMinutes`, `remainingMinutes`, `totalHours`, and `result`. b) **How many function calls are there?** - The template literal uses `${...}` expressions, but these are not function calls. From 479278e7a05e77bc0dd468634a1d7885871df9c2 Mon Sep 17 00:00:00 2001 From: Abayie Date: Fri, 18 Jul 2025 07:30:53 +0100 Subject: [PATCH 22/23] 1-count.js --- Sprint-1/1-key-exercises/1-count.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index ba7f8c4c8..f7e1f78c2 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -7,4 +7,5 @@ count = count + 1; /*Line 3 is reassigning variable count with a new value, in this case we're saying add 1 to whatever we already have in count, and so by using the console.log before and after the reassignment the we can tell new value of count is 1 +The "one-word" description of the programming operation in line 3 is IINCREMENT */ From 75cbeceb22ab6f7e86bc23639f5346ba8f469b85 Mon Sep 17 00:00:00 2001 From: Abayie Date: Fri, 18 Jul 2025 07:31:52 +0100 Subject: [PATCH 23/23] error --- Sprint-1/1-key-exercises/1-count.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index f7e1f78c2..4e4b2b7d4 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -7,5 +7,5 @@ count = count + 1; /*Line 3 is reassigning variable count with a new value, in this case we're saying add 1 to whatever we already have in count, and so by using the console.log before and after the reassignment the we can tell new value of count is 1 -The "one-word" description of the programming operation in line 3 is IINCREMENT +The "one-word" description of the programming operation in line 3 is INCREMENT */