From 57564ecd23932f01d5ac11cc9fbfee6d9b771c57 Mon Sep 17 00:00:00 2001 From: Alaa-Tagi Date: Mon, 29 Sep 2025 19:33:42 +0100 Subject: [PATCH 01/15] Adding two comments to describe line 3 --- 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..c408d20d6 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 + +// Line 3 is changing the value of the count variable by increasing 1 to its current value. +// The = operator is used to assign the new value back to the count variable. From defadad4f1b4623cb69b1fe5e03c1af60be53290 Mon Sep 17 00:00:00 2001 From: Alaa-Tagi Date: Mon, 29 Sep 2025 20:02:51 +0100 Subject: [PATCH 02/15] update the code by declaring new variable and function producing strings "CKJ" --- Sprint-1/1-key-exercises/2-initials.js | 8 ++++++-- 1 file changed, 6 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..599c438bf 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,11 @@ 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 = ``; +function getInitial(name) { + return name[0]; +} -// https://www.google.com/search?q=get+first+character+of+string+mdn +let initials = + getInitial(firstName) + getInitial(middleName) + getInitial(lastName); +console.log(initials); From ac6b0e4792fcfce5a41918f22a9e833f4a1bee15 Mon Sep 17 00:00:00 2001 From: Alaa-Tagi Date: Mon, 29 Sep 2025 21:08:19 +0100 Subject: [PATCH 03/15] Create variables dir and ext to show different part of filepath --- Sprint-1/1-key-exercises/3-paths.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28..71d130f06 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,7 @@ 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 = ; - -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +const dir = filePath.slice(0, lastSlashIndex); +console.log(`The dir part of ${filePath} is ${dir}`); +const ext = filePath.slice(filePath.lastIndexOf(".")); +console.log(`The ext part of ${filePath} is ${ext}`); From 637cf89451ac14bfbf222d461cecc8607deca4d3 Mon Sep 17 00:00:00 2001 From: Alaa-Tagi Date: Mon, 29 Sep 2025 21:58:45 +0100 Subject: [PATCH 04/15] adding comments to explain the code and adding line command to run the code --- Sprint-1/1-key-exercises/4-random.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..a4e5ee658 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,3 +7,9 @@ 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); +// num is a random integer between 1 and 100. +// Math.random() generates a random floating-point number between 0 and 1. +// Multiplying this by (maximum - minimum + 1) scales it to a range of 0 to 100. +// Math.floor() rounds down the result to the nearest integer number. +// Finally, adding minimum shifts the range to be between 1 and 100. From ca4da7c7765118a333f65dc72dc2478455593c09 Mon Sep 17 00:00:00 2001 From: Alaa-Tagi Date: Mon, 29 Sep 2025 22:16:11 +0100 Subject: [PATCH 05/15] convert the lines to a comment --- Sprint-1/2-mandatory-errors/0.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..997eae365 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? +*/ From 4793b3d1544dcdbb00d779c081422ee0e1fafaf4 Mon Sep 17 00:00:00 2001 From: Alaa-Tagi Date: Mon, 29 Sep 2025 22:31:54 +0100 Subject: [PATCH 06/15] changed 'const'with 'let' and update line 4 --- Sprint-1/2-mandatory-errors/1.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..0d4b2fdcb 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 -const age = 33; -age = age + 1; +let age = 30; // Change const to let to allow reassignment +age += 1; // Increment age by 1 +console.log(age); From 0e312da02ea4e698ecb18e785e5d221a6fe0767d Mon Sep 17 00:00:00 2001 From: Alaa-Tagi Date: Mon, 29 Sep 2025 22:39:27 +0100 Subject: [PATCH 07/15] finding the error --- Sprint-1/2-mandatory-errors/2.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..48309110d 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -3,3 +3,9 @@ console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; + +// The variable cityOfBirth should be declared before it is used in the console.log statement. +/* +const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); +*/ \ No newline at end of file From 709bed60f1cf9281de83bf5efc0505f42487eb6c Mon Sep 17 00:00:00 2001 From: Alaa-Tagi Date: Mon, 29 Sep 2025 23:11:39 +0100 Subject: [PATCH 08/15] Predict, consider the error and update the code. --- Sprint-1/2-mandatory-errors/3.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..dcd6fc5cc 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,7 @@ +/* The old 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 +9,16 @@ 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 + +/* My prediction: The code will give an error because the minus sign(-4) and slice works only with strings, not numbers. + +Consideration: The error is a TypeError: cardNumber.slice is not a function. mostly it was because I predicted that numbers do not have a slice method. About the minus sign, I have learned about positive and negative indexing in strings, now I can see the difference. + + +To fix this, we need to convert cardNumber to a string before calling the slice method. +*/ + +// Updated code: +const cardNumber = 4533787178994213; +const last4DigitsCorrected = cardNumber.toString().slice(-4); +console.log(last4DigitsCorrected); From 72a2ea25d05df5762baac30c34f9bf1064823450 Mon Sep 17 00:00:00 2001 From: Alaa-Tagi Date: Mon, 29 Sep 2025 23:19:58 +0100 Subject: [PATCH 09/15] Fix the code --- Sprint-1/2-mandatory-errors/4.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..9294537b5 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,13 @@ +/* + The old code: const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const 24hourClockTime = "08:53"; +console.log(24hourClockTime);*/ + +// It is giving a syntax error +// The reason is that variable names cannot start with a number + +// Updated code: +const hourClockTime12 = "20:53"; +const hourClockTime24 = "08:53"; +console.log(hourClockTime24, hourClockTime12); From dd95e0398731e59dcd1f20491cf17fc0fbb266b4 Mon Sep 17 00:00:00 2001 From: Alaa-Tagi Date: Tue, 30 Sep 2025 00:04:15 +0100 Subject: [PATCH 10/15] Reading the code and answering the questions --- .../1-percentage-change.js | 36 +++++++++++++++++++ 1 file changed, 36 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..6401edd42 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -13,10 +13,46 @@ 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: +// line 4: carPrice.replaceAll(",", "") +// line 4: Number(carPrice.replaceAll(",", "")) +//line 5: priceAfterOneYear.replaceAll("," "") +// line 5: Number(priceAfterOneYear.replaceAll("," "")) +// line 9: console.log(`The percentage change is ${percentageChange}`) + + + // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? +/* + It's a SyntaxError in line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));. + The error is occurring because there is a missing comma between the two arguments of the replaceAll function here ("," ""). + To fix this problem, we need to add a comma between the two arguments: replaceAll(",", ""). + */ + + // c) Identify all the lines that are variable reassignment statements +/*reusing the same variable carPrice but updating its value: +carPrice = Number(carPrice.replaceAll(",", "")); + +reusing the same variable priceAfterOneYear but updating its value: +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); +*/ + + // d) Identify all the lines that are variable declarations +/*declaring a new variable carPrice: +let carPrice = "10,000"; + +declaring a new variable priceAfterOneYear: +let priceAfterOneYear = "8,543"; +*/ + + // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +/* +The expression Number(carPrice.replaceAll(",", "")) is converting the carPrice string into a number. +The purpose of this expression is to get a numeric value for carPrice that can be used for calculations. +*/ From 5ae96f41ea3ccec04fa45d1eb443e862de08bcc4 Mon Sep 17 00:00:00 2001 From: Alaa-Tagi Date: Tue, 30 Sep 2025 13:03:41 +0100 Subject: [PATCH 11/15] Answering the required questions and testing the code --- .../3-mandatory-interpret/2-time-format.js | 38 +++++++++++++++++++ 1 file changed, 38 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..d3f74a424 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -12,14 +12,52 @@ console.log(result); // For the piece of code above, read the code and then answer the following questions // a) How many variable declarations are there in this program? +/* There are 6 variable declarations: +1.Line 1 : const movieLength. +2.Line 3 : const remainingSeconds. +3.Line 4 : const totalMinutes. +4.Line 6 : const remainingMinutes. +5.Line 7 : const totalHours. +6.Line 9 : const result. +*/ // b) How many function calls are there? +/* There is one function call: +Line 10 : console.log(). +*/ + // c) Using documentation, explain what the expression movieLength % 60 represents + +/* The movieLength represents the length of the movie in seconds, the operand % is remaining (Modulo) returns the remaining of the movieLength divided by 60(to convert sec into minutes) but it only gives the remaining of this operation. + */ + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +/* +The expression assigned to completed total minutes of the movie, by subtract the movie length in sec from the remaining seconds and divide the result by 60 to convert it to minutes +*/ + // e) What do you think the variable result represents? Can you think of a better name for this variable? +/* + The variable result display the total length of the movie in these form (Hours:Minutes:seconds) in string format. + + I can think of "MovieDuration" as a better name because it gives more description to the output. +*/ + // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer + +/* +I did experimenting the code by putting different value to the movieLength and it works just fine. + +test numbers and its outcomes: +1. 36000sec>> 10:0:0 +2. 120 sec >> 0:2:0 +3. 0 sec >> 0:0:0 +4. 555555.55sec >> 154:19:15.550000000046566 + +As the results show the code is working fine even with unexpected large numbers. +*/ From 774c4240c29470759ac0f860ee79619055ef85d1 Mon Sep 17 00:00:00 2001 From: Alaa-Tagi Date: Tue, 30 Sep 2025 13:46:42 +0100 Subject: [PATCH 12/15] Describe the code --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..8aae5651e 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -24,4 +24,9 @@ console.log(`£${pounds}.${pence}`); // 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" +// 1. const penceString = "399p": initialises a string variable with the value "399p". +// 2. const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1): represent to takes a substring from index 0 up to (but not including) penceString.length - 1. +// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): assign to ensures the numeric string is at least 3 characters long by adding leading zeros if needed. +// 4. const pounds = paddedPenceNumberString.substring( 0,paddedPenceNumberString.length - 2): Takes the substring from the start up to (but not including) the last two characters. +// 5. substring(length - 2) : use to returns the last two characters (the pence digits). padEnd(2, "0") would append trailing zeros if the result were shorter than 2. +// 6. console.log(`£${pounds}.${pence}`): assign to display the price in a human-readable pounds-and-pence format (£x.yy) From 771dc704e8b0ade59a9954574c64e6c7c6ab5142 Mon Sep 17 00:00:00 2001 From: Alaa-Tagi Date: Tue, 30 Sep 2025 14:19:58 +0100 Subject: [PATCH 13/15] Use Google Chrome console to test alert and prompt functions --- Sprint-1/4-stretch-explore/chrome.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feaf..52333cc5c 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -12,7 +12,12 @@ invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? +Answer: A pop up window displaying a text (Hello World!) will appear on the top and an OK button. It's a temporarily effect, but it required a user interaction to press OK before continuing. + 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`? + +Answer: A pop up window appears with a title and a question (What is your name?), also an answering space area. At the right down of the window there are two buttons to the user, Ok and cancel. +After typing myName and press OK the console display the answer(myName). From 84d68227ba2d78eb009352b3d21790483ee48a37 Mon Sep 17 00:00:00 2001 From: Alaa-Tagi Date: Tue, 30 Sep 2025 18:41:36 +0100 Subject: [PATCH 14/15] Complete the objects.md questions --- Sprint-1/4-stretch-explore/objects.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56..407335b03 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -6,11 +6,28 @@ Open the Chrome devtools Console, type in `console.log` and then hit enter What output do you get? +-The output : ƒ log() { [native code] } + Now enter just `console` in the Console, what output do you get back? +-The output : console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} + a lot of functions under it. + Try also entering `typeof console` -Answer the following questions: +-The output : object + +-Answer the following questions: What does `console` store? + +-Answer : console is an object with debugging methods. +It does not store variables or result. It provide methods for outputting , data , object and more. + What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? + +Answer: +-console is a built-in object. +-log and assert are properties of that object, specifically functions (methods). +-The console.assert() static method writes an error message to the console if the assertion is false. If the assertion is true, nothing happens. +-The console.log() static method outputs a message to the console. +-'.' means use this method from this object. From fb13fb78752ca23fd01ac210b2c8753ede1a16fe Mon Sep 17 00:00:00 2001 From: Alaa-Tagi Date: Tue, 7 Oct 2025 14:34:09 +0100 Subject: [PATCH 15/15] Fix Q: d --- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index 6401edd42..9eefffa1f 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -47,6 +47,12 @@ let carPrice = "10,000"; declaring a new variable priceAfterOneYear: let priceAfterOneYear = "8,543"; + +declaring a new variable priceDifference: +const priceDifference = carPrice - priceAfterOneYear; + +declaring a new variable percentageChange: +const percentageChange = (priceDifference / carPrice) * 100; */