From 4f906b13b438377753b7848a61ac9c2f74fa41f9 Mon Sep 17 00:00:00 2001 From: HoussamLh <156331030+HoussamLh@users.noreply.github.com> Date: Thu, 19 Jun 2025 07:48:08 +0100 Subject: [PATCH 01/20] Update 0.js Added comments to exclude instructional lines from execution --- Sprint-1/2-mandatory-errors/0.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..2dd55b437 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,12 @@ + // we can turn the lines into comments. we can use: + +// for single-line comments, or + +/* for multi-line comments. */ + +/* + This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +We don't want the computer to run these 2 lines - how can we solve this problem? + +*/ From 6bbd872229e4587617beafeefc0dde34b6fa04b3 Mon Sep 17 00:00:00 2001 From: HoussamLh <156331030+HoussamLh@users.noreply.github.com> Date: Thu, 19 Jun 2025 07:49:05 +0100 Subject: [PATCH 02/20] Update 1.js Updated age variable to let to allow incrementing its value. --- Sprint-1/2-mandatory-errors/1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..031839b47 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,4 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; From 80eefd3688640656ac5af2797776a67be5150795 Mon Sep 17 00:00:00 2001 From: HoussamLh <156331030+HoussamLh@users.noreply.github.com> Date: Thu, 19 Jun 2025 07:51:35 +0100 Subject: [PATCH 03/20] Update 2.js Declare variable before using in template string. --- Sprint-1/2-mandatory-errors/2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..3c58edaf8 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,5 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... -// what's the error ? +// what's the error ? The error here is due to using a variable before it's declared. console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; From 7f4d5bfe34827fe4ac5a6b444e9df4ec4d4ad554 Mon Sep 17 00:00:00 2001 From: HoussamLh <156331030+HoussamLh@users.noreply.github.com> Date: Thu, 19 Jun 2025 07:52:42 +0100 Subject: [PATCH 04/20] Update 3.js Add comments explaining slice error and fix by converting number to string. --- Sprint-1/2-mandatory-errors/3.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..c0ab368da 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,9 +1,22 @@ 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 -// Before running the code, make and explain a prediction about why the code won't work -// 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 + +// We want last4Digits to store the last 4 digits of cardNumber + +// Prediction before running: +// This will cause an error because cardNumber is a number, +// and numbers don't have the slice() method. slice() works only on strings or arrays. + +// Running the code would give: +// TypeError: cardNumber.slice is not a function + +// Why? +// Because slice() is not defined for numbers in JavaScript. + +// Fix: +// Convert cardNumber to a string first, so we can use slice() on it. +// Then slice the last 4 characters to get the last 4 digits. + +const last4Digits = String(cardNumber).slice(-4); + +console.log(last4Digits); // Output: 4213 + From cf582c5b964bed3621abf47932025773647f078a Mon Sep 17 00:00:00 2001 From: HoussamLh <156331030+HoussamLh@users.noreply.github.com> Date: Thu, 19 Jun 2025 07:55:57 +0100 Subject: [PATCH 05/20] Update 4.js Fix invalid variable names by renaming to start with letters instead of numbers. --- Sprint-1/2-mandatory-errors/4.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..5dc0c0828 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,14 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +// Original variable names are invalid because variable names cannot start with a number +// const 12HourClockTime = "20:53"; // This will cause a syntax error +// const 24hourClockTime = "08:53"; // Also invalid for the same reason + +// Fix: +// Variable names must start with a letter, underscore (_), or dollar sign ($). +// So we rename the variables to valid names below: + +const hour12ClockTime = "20:53"; // Valid variable name for 12-hour clock time +const hour24ClockTime = "08:53"; // Valid variable name for 24-hour clock time + +// Explanation: +// Variable names cannot begin with a number in JavaScript, +// so prefixing them with a letter or underscore solves the problem. From 3c9abddc57f99f8c53a906a05a356d4ab8f566c1 Mon Sep 17 00:00:00 2001 From: HoussamLh <156331030+HoussamLh@users.noreply.github.com> Date: Thu, 19 Jun 2025 08:07:12 +0100 Subject: [PATCH 06/20] Update 1-percentage-change.js Add missing comma to replaceAll so the code runs smoothly. --- .../1-percentage-change.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..b246796d2 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -11,12 +11,41 @@ console.log(`The percentage change is ${percentageChange}`); // Read the code and then answer the questions below +// --- Answers to the questions --- + // a) How many function calls are there in this file? Write down all the lines where a function call is made +// Function calls: +// - Line 4: carPrice.replaceAll(",", "") +// - Line 4: Number(...) +// - Line 5: priceAfterOneYear.replaceAll("," "") --> syntax error here +// - Line 5: Number(...) +// - Line 10: 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? +// Error at line 5: SyntaxError due to missing comma in replaceAll arguments +// Fix: add the missing comma inside replaceAll: +// priceAfterOneYear.replaceAll(",", "") + // c) Identify all the lines that are variable reassignment statements +// Reassignments: +// - Line 4: carPrice = Number(...) +// - Line 5: priceAfterOneYear = Number(...) + // d) Identify all the lines that are variable declarations +// Declarations: +// - Line 1: let carPrice = "10,000"; +// - Line 2: let priceAfterOneYear = "8,543"; +// - Line 7: const priceDifference = ... +// - Line 10: const percentageChange = ... + // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? + +// Explanation: +// - carPrice.replaceAll(",","") removes all commas from the string "10,000", turning it into "10000". +// - Number(...) converts the resulting string "10000" into the numeric value 10000. +// This allows mathematical operations on carPrice, which is originally a formatted string. + From b276dfbc38309445eafc968ebc7872ba022e653e Mon Sep 17 00:00:00 2001 From: HoussamLh <156331030+HoussamLh@users.noreply.github.com> Date: Thu, 19 Jun 2025 08:09:57 +0100 Subject: [PATCH 07/20] Update 2-time-format.js Add detailed comments answering questions about movie length time calculation. --- .../3-mandatory-interpret/2-time-format.js | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..877791aa2 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -9,17 +9,36 @@ const totalHours = (totalMinutes - remainingMinutes) / 60; const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; console.log(result); -// For the piece of code above, read the code and then answer the following questions +// --- Answers to the questions --- // a) How many variable declarations are there in this program? +// There are 6 variable declarations: +// movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, and result // b) How many function calls are there? +// There is 1 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 +// The `%` operator is the modulo operator, which returns the remainder after division. +// So movieLength % 60 gives the remainder when movieLength is divided by 60. +// This means it calculates the leftover seconds after counting full minutes. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// Line 4: (movieLength - remainingSeconds) / 60 +// This subtracts the leftover seconds from the total seconds, +// giving a multiple of 60 seconds (full minutes), +// then divides by 60 to convert seconds to total minutes. // e) What do you think the variable result represents? Can you think of a better name for this variable? +// result holds the formatted string showing the movie length in "hours:minutes:seconds" format. +// A better name might be `formattedTime` or `movieDurationFormatted`. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// For positive integers, the code works correctly. +// For zero, it returns "0:0:0", which is fine. +// For negative numbers, the calculation may produce unexpected negative values. +// For very large values, it still works fine. +// The code assumes movieLength is an integer number of seconds. +// If movieLength is a non-integer or not a number, the code might not behave as expected. + From b50a6c4b0a7f7e32dc0791de2c5cba7123f31054 Mon Sep 17 00:00:00 2001 From: HoussamLh <156331030+HoussamLh@users.noreply.github.com> Date: Thu, 19 Jun 2025 08:11:41 +0100 Subject: [PATCH 08/20] Update 3-to-pounds.js Add detailed comments explaining step-by-step price formatting from pence string. --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..08e219e09 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -1,27 +1,31 @@ const penceString = "399p"; +// 1. Initializes a string variable with the value "399p" representing the price in pence with a trailing 'p'. const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1 ); +// 2. Removes the trailing 'p' by taking a substring from index 0 up to (but not including) the last character. +// Result: "399" const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +// 3. Ensures the string is at least 3 characters long by padding with leading zeros if needed. +// In this case, "399" is already 3 characters, so it remains "399". + const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2 ); +// 4. Extracts the pounds part by taking all characters except the last two. +// For "399", this is "3" (the hundreds place). const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0"); +// 5. Extracts the last two characters as the pence part. +// For "399", this is "99". +// Then pads the string on the right with zeros if it’s shorter than 2 characters (not needed here). console.log(`£${pounds}.${pence}`); - -// This program takes a string representing a price in pence -// The program then builds up a string representing the price in pounds - -// You need to do a step-by-step breakdown of each line in this program -// Try and describe the purpose / rationale behind each step - -// To begin, we can start with -// 1. const penceString = "399p": initialises a string variable with the value "399p" +// 6. Prints the formatted price string with a £ sign, pounds, and pence separated by a dot. +// Output: "£3.99" From b98039044534c2c0f0136e2ac589c5cac9648ea1 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 6 Jul 2025 16:18:57 +0100 Subject: [PATCH 09/20] I believe that I've done the sprint one --- Sprint-1/4-stretch-explore/chrome.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feaf..66159fce8 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -10,9 +10,17 @@ Let's try an example. In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; -What effect does calling the `alert` function have? +What effect does calling the `alert` function have? It opens a popup message box in the browser with the text: +You must click "OK" to dismiss it before you can do anything else on the page. 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 effect does calling the `prompt` function have? It opens a popup input box asking: +What is your name? +and I can enter a response, then click "OK" or "Cancel". + +What is the return value of `prompt`? Return value: + +If I enter a name (e.g., "Sami") and press OK, it returns the string: "Sami" + +If I press Cancel, it returns: null \ No newline at end of file From 7d43c64d99482704b6b82f0ca80e59c4f33d8694 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 6 Jul 2025 16:20:58 +0100 Subject: [PATCH 10/20] i'm just checking if this work. --- 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 117bcb2b6..4ecd59d66 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,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 +// \ No newline at end of file From 0284fac18b4dc98483f1f8fc0f8eecab087f5fa8 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 6 Jul 2025 16:23:39 +0100 Subject: [PATCH 11/20] I've done the first part of sprint 1 --- Sprint-1/1-key-exercises/4-random.js | 75 ++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..04a0e0a07 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -3,7 +3,74 @@ const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; -// In this exercise, you will need to work out what num represents? -// Try breaking down the expression and using documentation to explain what it means -// It will help to think about the order in which expressions are evaluated -// Try logging the value of num and running the program several times to build an idea of what the program is doing +// 1- In this exercise, you will need to work out what num represents? + +// the num gives a random whole number between 1 and 100 like 73, 12, or 100. + +// 2- Try breaking down the expression and using documentation to explain what it means +/* + +1. Math.random() + +Returns a random decimal number between 0 and 1 but never gives 1.0. + +Example: 0.24 + +2. (maximum - minimum + 1) + +This gives number of possible values. + +Without the +1, we'd only get the difference, not the full count. + +for example: + +5 - 1 = 4 → but there are actually 5 numbers: 1, 2, 3, 4, 5 + +So we add +1 to include both ends of the range. + +3. Math.random() * (maximum - minimum + 1) + +This gives a random decimal number between 0 and 100 (like 24, 65 ...) + +Because we want the random decimal scaled to the size of the range of possible values. + +For example, if we want a number between 1 and 100 (inclusive), there are 100 possible numbers (1, 2, ..., 100). + +Multiplying by 100 means the decimal is scaled up to cover all those possibilities before rounding. + +4. Math.floor(...) + +This rounds the decimal down to the nearest whole number. + +Example: Math.floor(78.43) → 78 + +5. + minimum + +we add the minimum to shift the range correctly, and make sure the random number up to start from minimum. + +5-1- for example if we remove the + minimum + +5-1-1 Math.random() 0.9999 * 99 + 1 → only goes up to 99.999... → max = 99.999... → floor = 100 (but very unlikely) + +now 100 becomes very hard to reach, and in many cases, you never get it. + +5-1-2 Math.random() 0.00 * 99 + 1 → only goes up to 0... → max = 0... → floor = 0 (now the minimum is 0, and can appears) + +conclusion : when we don’t add + minimum, there is a chance that 1 appears, but it’s not the guaranteed minimum anymore — + +and the range starts at 0, not 1. + +5-2- when we add +minimum + +now we make sure the min and max can appear in the final results and make sure the minimum is 1 not 0. + +Minimum appears when random = 0 + +Maximum appears when random is almost 1 (like 0.9999...). + +example : Math.random() * 99 + 1 → up to 0.99 → max = 99 → floor = 99 → +1 = 100 (so more possibilities for 100 to appears) + +*/ + +//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 From ba702df9d825df4a73b69978dfd9c09c571217dd Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 13 Jul 2025 11:08:20 +0100 Subject: [PATCH 12/20] describe what line 3 is doing --- 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 4ecd59d66..f60a006be 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,4 +4,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 -// \ No newline at end of file +// line 3 is increases the value of count by 1 and saves the updated value back into count \ No newline at end of file From 78d0604992bca37b5e874f693a11ed2051f63292 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 13 Jul 2025 11:12:19 +0100 Subject: [PATCH 13/20] describe line 3 what is doing --- 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 f60a006be..9975c5815 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,4 +4,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 -// line 3 is increases the value of count by 1 and saves the updated value back into count \ No newline at end of file +// line 3 is increases the value of count by 1 and saves the updated value back into count variable. \ No newline at end of file From af998dd2355f7641eea3483acf3decf928124a9e Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 13 Jul 2025 11:16:45 +0100 Subject: [PATCH 14/20] Declare a variable called initials that stores the first character of each string. --- Sprint-1/1-key-exercises/2-initials.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f617..873e2f039 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 = ``; -// https://www.google.com/search?q=get+first+character+of+string+mdn +let initials = firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0); + +console.log(initials); + +// https://www.google.com/search?q=get+first+character+of+string+mdn From 7623716994a0d30bc2bf2748ad416a2750e1bb22 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 13 Jul 2025 11:20:33 +0100 Subject: [PATCH 15/20] Create two variables that store the dir part of the filePath variable and store the ext part of the variable --- Sprint-1/1-key-exercises/3-paths.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28..4daa0d8d9 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,8 @@ 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(".") + 1); + // https://www.google.com/search?q=slice+mdn \ No newline at end of file From 6a8fc1c14a5bcaf812535ba881e8bfe671930438 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 13 Jul 2025 11:25:37 +0100 Subject: [PATCH 16/20] how we can make sure the computer ignores the lines using comments --- Sprint-1/2-mandatory-errors/0.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index 2dd55b437..40558a17b 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -10,3 +10,7 @@ This is just an instruction for the first activity - but it is just for human co We don't want the computer to run these 2 lines - how can we solve this problem? */ + +// we can use comments to make sure the computer ignores the lines, comment them out using : + +// // single line or /* multi-line */. From 1b0b5b3113b2c55d90985fc94a51f456b673ea0f Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 13 Jul 2025 11:34:35 +0100 Subject: [PATCH 17/20] I've changed const to let for age variable to allow reassignment --- Sprint-1/2-mandatory-errors/1.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 031839b47..3e3c51959 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,5 @@ -// trying to create an age variable and then reassign the value by 1 +// Trying to create an age variable and then reassign the value by 1 -let age = 33; -age = age + 1; +let age = 33; // Declare a variable called age and assign it the value 33 +age = age + 1; // Reassign age to be its current value plus 1 +console.log(age); // Output: 34 From d477732a5048cd134a81b472e941003b3b47b9f0 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 13 Jul 2025 11:38:40 +0100 Subject: [PATCH 18/20] move variable declaration before use to avoid ReferenceError --- Sprint-1/2-mandatory-errors/2.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index 3c58edaf8..bb4f4f3d8 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,7 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? The error here is due to using a variable before it's declared. -console.log(`I was born in ${cityOfBirth}`); + +// Fixed: Declare the variable before using it const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); \ No newline at end of file From 2a3147019cf3952b64fd242bc8c0aac1e27a9548 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 13 Jul 2025 11:58:17 +0100 Subject: [PATCH 19/20] explore console object and method access using dot notation --- Sprint-1/4-stretch-explore/objects.md | 44 ++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56..2ad75a93f 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -4,13 +4,55 @@ In this activity, we'll explore some additional concepts that you'll encounter i Open the Chrome devtools Console, type in `console.log` and then hit enter -What output do you get? +What output do you get? +1. it show something like: +ƒ log() { [native code] } +This tells you that console.log is a function. Specifically, it's a built-in JavaScript function used to print messages to the console. Now enter just `console` in the Console, what output do you get back? +2. it show something like this: +console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} +It shows a list of functions and properties, like log, error, warn, assert, clear, etc. +This tells you that console is a built-in object that stores useful debugging tools. Try also entering `typeof console` +3. it show "object" +This confirms that console is an object in JavaScript. Answer the following questions: What does `console` store? What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? + + + + +Answering the Questions: +1. What does console store? +console is a JavaScript object that contains methods (functions) used mainly for debugging. + +It stores functions like: + +console.log() – logs messages + +And others like console.clear(), console.table(), etc. + +2. What does console.log or console.assert mean? +These are method calls on the console object. + +console.log means: access the log property (a function) that is stored inside the console object. + +console.log() means: call that function. + +console.assert() is similar but only logs when a condition is false. + +3. What does the . (dot) mean in JavaScript? +The dot is the member access operator. + +It means: "get the property named X from this object". + +So: + +console.log → get the log function from the console object. + +console.log("sami") → run the log function with the argument "sami". \ No newline at end of file From 64a6dc6a9dada24c88a7093f5366a3c6200adb7f Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 13 Jul 2025 12:04:19 +0100 Subject: [PATCH 20/20] test alert and prompt functions in Chrome V8 Console --- Sprint-1/4-stretch-explore/chrome.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index 66159fce8..91623257c 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -10,16 +10,22 @@ Let's try an example. In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; -What effect does calling the `alert` function have? It opens a popup message box in the browser with the text: +1. What effect does calling the `alert` function have? + +It opens a popup message box in the browser with the text: You must click "OK" to dismiss it before you can do anything else on the page. -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`. +2. 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`. + +3. What effect does calling the `prompt` function have? -What effect does calling the `prompt` function have? It opens a popup input box asking: +It opens a popup input box asking: What is your name? and I can enter a response, then click "OK" or "Cancel". -What is the return value of `prompt`? Return value: +4. What is the return value of `prompt`? Return value: If I enter a name (e.g., "Sami") and press OK, it returns the string: "Sami"