From 9c9c8946ca759cb999042b8bd1ace4ce83ce78bc Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Fri, 27 Feb 2026 23:34:21 +0000 Subject: [PATCH 01/19] 1-count.js committed --- 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 117bcb2b6e..423f77aaf2 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,6 @@ 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 + +/* The line 3 is increasing the variable count by 1 and assigning the result to count variable on the left hand * side. + */ From 93a764cc174dd8a5d2f0420d923dd4da262dd060 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Fri, 27 Feb 2026 23:37:06 +0000 Subject: [PATCH 02/19] 2-initials.js committed --- Sprint-1/1-key-exercises/2-initials.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f6175..73d5c29757 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,8 @@ 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[0]}${middleName[0]}${lastName[0]}`; +console.log(initials); // https://www.google.com/search?q=get+first+character+of+string+mdn From 0b13c158042ce05a0ac7f46f6a7c42241036440d Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Fri, 27 Feb 2026 23:45:28 +0000 Subject: [PATCH 03/19] 3-paths.js committed --- Sprint-1/1-key-exercises/3-paths.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28e..dc2bc8acce 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -1,3 +1,4 @@ +/** // The diagram below shows the different names for parts of a file path on a Unix operating system // ┌─────────────────────┬────────────┐ @@ -20,4 +21,21 @@ console.log(`The base part of ${filePath} is ${base}`); const dir = ; const ext = ; -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// https://www.google.com/search?q=slice+mdn +*/ + +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 +const dir = filePath.slice(0, lastSlashIndex + 1); + +// Create a variable to store the ext part of the variable +const lastDotIndex = base.lastIndexOf("."); +const ext = lastDotIndex !== -1 ? base.slice(lastDotIndex) : ""; + +console.log(`The dir part is: ${dir}`); +console.log(`The extension is: ${ext}`); + From 96b6f9b68ded920d1d0a671808dc96c1870f3e59 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Fri, 27 Feb 2026 23:58:37 +0000 Subject: [PATCH 04/19] 4-random.js committed --- Sprint-1/1-key-exercises/4-random.js | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aabb..dcf215fc67 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,3 +7,56 @@ 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 + +/** + * Answear: + * + * 1. The constants + * + * const minimum = 1; + * const maximum = 100; + * These are the lowest and highest possible values for the random number we are generating. + * + * 2. The expression inside Math.random() + * + * Math.random() + * + * This returns a pseudo-random number between 0 (inclusive) and 1 (exclusive). + * So it could be 0.1234, 0.9876, etc., but never exactly 1. + * + * 3. Inside Math.floor() + * + * Math.random() * (maximum - minimum + 1) + minimum + * + * First, we compute: + * + * (maximum - minimum + 1) + * + * With minimum = 1, maximum = 100, this is: + * 100 - 1 + 1 = 100 + * So it’s 100. This is the total number of possible integers from 1 to 100 inclusive. + * So the expression becomes: + * + * 4. The range of values + * + * Let’s check possible values step by step: + * + * Case 1: smallest possible random = 0 + * 0 * 100 + 1 = 1 + * + * Case 2: largest possible random = 0.999… (less than 1) + * 0.999… * 100 = 99.999… + * 99.999… + 1 = 100.999… + * + * But Math.floor() will round down to the nearest integer. + * + * 5. Applying Math.floor() + * + * If we get a result of 100.999… after multiplication and addition, Math.floor(100.999…) gives 100. + * If we get a result of 1.0 (or just over 1 up to 1.999…), Math.floor() gives 1. + * So the possible final num values after Math.floor() are 1, 2, 3, …, 100. + * + * 6. Conclusion + * The code generates a random integer between minimum (1) and maximum (100), inclusive of both. + * So num represents: + * A random whole number from 1 to 100. From da4cf4c040fde350dc787d7fb996df5e4b904245 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Sat, 28 Feb 2026 00:06:46 +0000 Subject: [PATCH 05/19] 0.js committed --- Sprint-1/2-mandatory-errors/0.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f7..4f1cd20bb7 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,6 @@ -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? + +/** + * The // tells JavaScript to ignore everything after it on that line, so the computer will not try to execute these instructions as code, but it remains visible for humans to read and understand the program. + */ From d2f6fa0035772b0cec7b62f2e5f62e98cc1449c4 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Sat, 28 Feb 2026 00:17:21 +0000 Subject: [PATCH 06/19] 1.js committed --- Sprint-1/2-mandatory-errors/1.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea76..0344e69f52 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,16 @@ +/** // trying to create an age variable and then reassign the value by 1 const age = 33; age = age + 1; +*/ + +/** + * There's a problem with your code. It's trying to reassign a value to a const variable, which is not allowed in JavaScript as const variables cannot be changed after they're declared. + * To fix this, you should use let instead: +*/ + +// trying to create an age variable and then reassign the value by 1 using the keywork 'let' instead of 'const' + +let age = 33; +age = age + 1; From e6761d2890016a0f82db186806326ffd0f895946 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Sat, 28 Feb 2026 00:17:36 +0000 Subject: [PATCH 07/19] 2.js committed --- Sprint-1/2-mandatory-errors/2.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831d..05c37525ad 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,23 @@ +/** + * // 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"; +*/ + +/** + * The error is that you're trying to use the variable cityOfBirth in the template literal before it has been declared and initialized. + +In JavaScript, you cannot access a const variable before its declaration. This creates a Temporal Dead Zone (TDZ) error. + +Fix: Move the console.log statement after the variable declaration: +*/ + +// Currently trying to print the string "I was born in Bolton" but it isn't working... +// what's the error ? + +const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); + From b18653b3918a5cf57b3a113a1691ff3101a68d94 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Sat, 28 Feb 2026 12:46:23 +0000 Subject: [PATCH 08/19] 1.js changed const variable to let variable --- Sprint-1/2-mandatory-errors/1.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 0344e69f52..513db73e1b 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -7,6 +7,7 @@ age = age + 1; /** * There's a problem with your code. It's trying to reassign a value to a const variable, which is not allowed in JavaScript as const variables cannot be changed after they're declared. + * It returns a 'TypeError: Assignment to constant variable' * To fix this, you should use let instead: */ From 8d8f9c871b1e6b8a36f620df6f386080df5ca1fc Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Mon, 2 Mar 2026 22:31:01 +0000 Subject: [PATCH 09/19] Add .swp on .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bde36e5302..3f87afb450 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules .DS_Store .vscode -**/.DS_Store \ No newline at end of file +*.swp +**/.DS_Store From a21e52a5dd8e99cc2db6089804bfc58a31a5d51c Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Mon, 2 Mar 2026 22:32:09 +0000 Subject: [PATCH 10/19] 4-random.js committed --- Sprint-1/1-key-exercises/4-random.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index dcf215fc67..2a1a81c874 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -3,6 +3,8 @@ const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; +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 // It will help to think about the order in which expressions are evaluated @@ -60,3 +62,5 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; * The code generates a random integer between minimum (1) and maximum (100), inclusive of both. * So num represents: * A random whole number from 1 to 100. + */ + From 8c32fc3347c1cb677c6329988da9aeeaba1572b1 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Mon, 2 Mar 2026 22:41:34 +0000 Subject: [PATCH 11/19] Changed 'we should' for 'it should' as it makes the code more intuitive --- 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 513db73e1b..246633630e 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -8,7 +8,7 @@ age = age + 1; /** * There's a problem with your code. It's trying to reassign a value to a const variable, which is not allowed in JavaScript as const variables cannot be changed after they're declared. * It returns a 'TypeError: Assignment to constant variable' - * To fix this, you should use let instead: + * To fix this, it should use let instead: */ // trying to create an age variable and then reassign the value by 1 using the keywork 'let' instead of 'const' From 1b7863b3d4c0138e2c1a5422b218a021b19a3583 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Mon, 2 Mar 2026 22:59:20 +0000 Subject: [PATCH 12/19] 2.jscommitted --- 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 05c37525ad..1723bdf402 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -10,7 +10,7 @@ const cityOfBirth = "Bolton"; /** * The error is that you're trying to use the variable cityOfBirth in the template literal before it has been declared and initialized. -In JavaScript, you cannot access a const variable before its declaration. This creates a Temporal Dead Zone (TDZ) error. +In JavaScript, you cannot access a const variable before its declaration. This creates what it's callled in JavaScript a Temporal Dead Zone (TDZ) error. Fix: Move the console.log statement after the variable declaration: */ @@ -18,6 +18,9 @@ Fix: Move the console.log statement after the variable declaration: // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? +// The error is: +// ReferenceError: Cannot access 'cityOfBirth' before initialization + const cityOfBirth = "Bolton"; console.log(`I was born in ${cityOfBirth}`); From 250c21fc2644402202d3178b1be0632bf39e47dd Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Mon, 2 Mar 2026 22:59:33 +0000 Subject: [PATCH 13/19] 3.jscommitted --- Sprint-1/2-mandatory-errors/3.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884db..726aa85a28 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,8 @@ +/** Original code: + * 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 +10,31 @@ 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 +The code won't work because cardNumber is defined as a number (4533787178994213), but the .slice() method is a string method. Numbers don't have a .slice() method. +When the code runs, JavaScript will throw a TypeError saying: +cardNumber.slice is not a function +*/ + +/** + * Running: + * When running the code we get. + * TypeError: cardNumber.slice is not a function + * + * This matches prediction above that the error occurs because we're trying to use a string method on a number. + */ + +/** + * Why the error occurs: +.slice() is a method that belongs to the String and Array prototypes, not the Number prototype. When JavaScript tries to execute cardNumber.slice(-4), it looks for a slice property on the number object, and can't find it, and throws a TypeError message. + */ + +/** Fixing the code +To get the last 4 digits correctly, we need to convert the number to a string first then performs the operation. +*/ + +const cardNumber = 4533787178994213; +const last4Digits = cardNumber.toString().slice(-4); + +console.log(last4Digits); // "4213" From 5795f102dfa02722d04796a9394afd33d53906db Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Mon, 2 Mar 2026 23:04:12 +0000 Subject: [PATCH 14/19] 4.js committed --- Sprint-1/2-mandatory-errors/4.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d1..7597487046 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,12 @@ +/** const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const 24hourClockTime = "08:53"; +*/ + +/** + * In JavaScript, variable names cannot start with a number. They must begin with a letter, underscore (_), or dollar sign ($). + */ + +// Here the correct version +const twelveHourClockTime = "20:53"; +const twentyFourHourClockTime = "08:53"; From 3f1bc2fb572b3b7b2f6ad371db79683fbf113e26 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Mon, 2 Mar 2026 23:54:43 +0000 Subject: [PATCH 15/19] 1-percentage-change.js committed --- .../1-percentage-change.js | 46 +++++++++++++++++++ 1 file changed, 46 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..47b7311973 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -13,10 +13,56 @@ 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 5 function calls in this file: + + * carPrice.replaceAll(",", "") - Line 4 + * Number() (enclosing the replaceAll result) - Line 4 + * priceAfterOneYear.replaceAll("," "") - Line 5 (contains a syntax error but is intended as a function call) + * Number() (wrapping the replaceAll result) - Line 5 (intended as a function call) + * console.log() - 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? +/** + * Error location: Line 5 + + * Why the error occurs: + * There's a syntax error on line 5 - a comma is missing between the parameters in the replaceAll() method. The * code shows replaceAll("," "") but should be replaceAll(",", ""). + * + * How to fix: + * Add a comma between the parameters: + */ + // c) Identify all the lines that are variable reassignment statements +/** + * Lines with variable reassignment: + * Line 4: carPrice = Number(carPrice.replaceAll(",", "")); + * Line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); (after fixing the syntax error) + * These lines reassign new values to the existing variables. + */ + // d) Identify all the lines that are variable declarations +/** + * Lines with variable declarations: + + * Line 1: let carPrice = "10,000"; + * Line 2: let priceAfterOneYear = "8,543"; + * Line 7: const priceDifference = carPrice - priceAfterOneYear; + * Line 8: const percentageChange = (priceDifference / carPrice) * 100; + */ + // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? + +/** + * This expression performs two operations: + * + * carPrice.replaceAll(",", ""). + * It removes all commas from the string "10,000", converting it to "10000" (a string without commas) + * Number() - Converts the resulting string "10000" into an actual number type (10000) + * Ojective: The overall purpose is to convert a formatted price string (like "10,000") into a numeric value that can be used for mathematical calculations. This allows the code to properly calculate the price difference and percentage change, which wouldn't work correctly with the original string values. + */ + From 81e6213a6472270e597ddb880750400aedfe3a79 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Mon, 2 Mar 2026 23:54:59 +0000 Subject: [PATCH 16/19] 2-time-format.js committed --- .../3-mandatory-interpret/2-time-format.js | 50 +++++++++++++++++++ 1 file changed, 50 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..a7b04016fd 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -13,13 +13,63 @@ console.log(result); // a) How many variable declarations are there in this program? +/** + * There are five variable declarations. Here are: + * movieLength + * remainingSeconds + * totalMinutes + * remainingMinutes + * totalHours + */ + // b) How many function calls are there? +/** + * There is one function 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 +/** + * Based on the provided documentation from MDN, I can explain what the expression `movieLength % 60` represents. According to the "Arithmetic operators" section of the MDN document linked, the `%` operator is the "Remainder operator". + It returns the remainder left over when one operand (the left one, `movieLength`) is divided by a second operand (the right one, `60`). +In the context of the code: + `movieLength` stores a duration in seconds (8784). + Dividing `8784` by `60` tells how many whole minutes are in that duration, however it doesn't divide evenly all the time. + `movieLength % 60` specifically calculates the leftover seconds that do not form a full minute. + Based on the example of 8784 seconds: + 8784 ÷ 60 = 146 minutes with a remainder. + 60 * 146 = 8760 seconds. + 8784 - 8760 = 24 seconds. + Therefore, this expression correctly isolates the seconds component of the total time duration, which is then stored in the `remainingSeconds` variable. + */ + // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +/** + * Line 4 is const totalMinutes = (movieLength - remainingSeconds) / 60;. + * + * This expression first subtracts the remainingSeconds from the total movieLength. + * This results in a number of seconds that is perfectly divisible by 60. + * Then, it divides that number by 60 to convert it into the total number of whole minutes represented by the movie's length. + */ + // e) What do you think the variable result represents? Can you think of a better name for this variable? +/** + * The result variable represents the movie's length formatted as a string in the traditional hours:minutes:seconds format (e.g., "2:26:24" for a movie length of 8784 seconds). + * A better, more descriptive name for this variable would be formattedDuration or timeString. This makes its + * purpose clearer to anyone reading the code. + */ + // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer + +/** + * This code will work for all non-negative integer values of movieLength, but the output format might not always be the most appropriate. Here's the reason:: + + * For very short movies (e.g., 45 seconds): It will output "0:0:45". The hours and minutes are shown as single digits, which is technically correct but not the typical "00:00:45" format often expected. + * For durations with zero seconds (e.g., 3600 seconds = 1 hour): It will output "1:0:0". + * Potential problem: If movieLength were a negative number or not a number (e.g., a string), the code would either produce a negative time or result in an error like NaN (Not-a-Number), which wouldn't make sense. + * The code assumes the input is a valid positive number of seconds. + */ From cf82eb5b6b827c431dcf6921f2ef8718a0295094 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Mon, 2 Mar 2026 23:55:22 +0000 Subject: [PATCH 17/19] 3-to-pounds.js committed --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69a..6bde033c1a 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,51 @@ 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"; +Initialises a constant string variable with the value "399p". This represents a price in pence, with the "p" suffix indicating it's in pence (like writing "399p" on a price tag that can be found in shops in the UK). + + * 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1); + * Removes the trailing "p" character by taking a substring from index 0 to the second-last character. With "399p": + + * penceString.length = 4 + * penceString.length - 1 = 3 + * Takes characters from index 0 to 2 (inclusive) showing "399" + + * 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +Pads the number string from the left with zeros to ensure it's at least 3 characters long. This handles cases where the pence value might be less than 100 (e.g., "5p" would become "005"). + + * "399" is already 3 characters, so it remains "399" + + * 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2); + * Extracts the pounds part by taking all characters except the last two (the pence part). "399": + + * paddedPenceNumberString.length = 3 + * paddedPenceNumberString.length - 2 = 1 + + * Takes characters from index 0 to 0 (inclusive) "3" + + * 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); + * Extracts the pence part (last two characters) and ensures it's exactly 2 digits by padding from the right with zeros if needed. + * paddedPenceNumberString.substring(1). Takes from index 1 to end "99" + * Since "99" is already 2 characters, padEnd(2, "0") leaves it as "99" + + * 6. console.log(£${pounds}.${pence}); + * Outputs the formatted price in pounds, combining: + + * £ symbol + + * pounds value ("3") + * decimal point + * pence value ("99") + * Result: "£3.99" + + * Purpose/Rationale + * + * The program converts a pence-based price string (like "399p") into a properly formatted pounds and pence representation (£3.99). The padding operations ensure that: + + * Small pence values (like "5p") are correctly formatted as £0.05 + * The pence portion always shows two digits (e.g., "99" not "9") + * The pounds part correctly handles amounts under £1 (shows as "0") + */ From 8d61f8c5421f478fffcea6609ed77f62911703a3 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Tue, 3 Mar 2026 00:16:13 +0000 Subject: [PATCH 18/19] chrome.md and objects.md committed --- Sprint-1/4-stretch-explore/chrome.md | 34 +++++++++++++++++++ Sprint-1/4-stretch-explore/objects.md | 47 +++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feafe..655c479e91 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -16,3 +16,37 @@ Now try invoking the function `prompt` with a string input of `"What is your nam What effect does calling the `prompt` function have? What is the return value of `prompt`? + +Response: + +1. Call the alert function +In the console, typing 'alert("Hello world!");' + +Effect: +A small pop-up dialog box appears in the browser window with the message "Hello world!" and an OK button. The dialog is modal, so it blocks interaction with the web page until you click OK. + +2. Call the prompt function typing: + +let myName = prompt("What is your name?"); + +Effect: +Another pop-up appears, this time with the message "What is your name?", a text input field, and OK/Cancel buttons. + +When typed something and press OK, the string typed is returned and stored in the variable myName. +If pressed Cancel or close the dialog without entering anything, the return value is null. + +3. Check the return value +After entering a name (e.g., "Carlos") and clicking OK, you can check: + +console.log(myName); +Output in the console: + +Carlos + +In summary: +alert() displays a message and returns nothing (undefined). +prompt() displays a message with an input field and returns either of one value: + +The input string (if OK is clicked) +null (if Cancel is clicked or the dialog is closed without input) + diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56a..2556d3d395 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -6,11 +6,58 @@ Open the Chrome devtools Console, type in `console.log` and then hit enter What output do you get? +When you typed console.log in the Console and hit Enter, shows something like: + +ƒ log() { [native code] } +This shows that console.log is a function (indicated by the ƒ symbol) that's built into the browser (hence "[native code]"). + Now enter just `console` in the Console, what output do you get back? +When typed console in the Console, it displays an object that looks something like: + +Console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} +This shows that console is an object containing many methods. + Try also entering `typeof console` +Typing typeof console returns: + +"object" +This confirms that console is an object data type. + +console stores a collection of methods and properties used for debugging and logging information in the browser. It's a built-in object that provides access to the browser's debugging console. It contains methods like: + +log() - for general output + +error() - for error messages + +warn() - for warnings + +info() - for informational messages + +assert() - for conditional logging + +table() - for displaying tabular data + +clear() - for clearing the console + +And many more + Answer the following questions: What does `console` store? What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? + +The dot (.) is the member access operator (also called the property accessor) in JavaScript. + +When it shows console.log: + +console is the object + +. means "access a property of this object" + +log is a property of the console object (specifically a method, which is a function stored as a property) + +So console.log means "access the log property of the console object." Since log is a function, we can then call it with parentheses: console.log("Hello"). +This dot notation is how JavaScript allows objects to contain related data and functionality, organizing code into logical groups. + From 488ef4ce69220d2564735960f841d9be9353dd54 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Tue, 3 Mar 2026 16:05:41 +0000 Subject: [PATCH 19/19] 1-percentage-change.js committed adding a comma --- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 2 +- 1 file changed, 1 insertion(+), 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 47b7311973..3577ef90ad 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;