From c16f93fd0752ddf181d6e157529c70a9b15ac732 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Tue, 21 Oct 2025 11:10:37 +0100 Subject: [PATCH 01/10] 1st & 2nd are completed. --- Sprint-1/1-key-exercises/1-count.js | 1 + Sprint-1/1-key-exercises/2-initials.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..2238bfd9c 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 +// Line 3 take the count and add 1 to that so as the count was 0 line 3 make it 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..c989b43d9 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -4,8 +4,9 @@ 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.charAt(0) + middleName.charAt(0) + lastName.charAt(0); -let initials = ``; + console.log(initials); // https://www.google.com/search?q=get+first+character+of+string+mdn From baf638314ac0a193cbc23c780380aa61050d4896 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Tue, 21 Oct 2025 11:33:17 +0100 Subject: [PATCH 02/10] 3rd is completed --- Sprint-1/1-key-exercises/3-paths.js | 8 ++++++-- 1 file changed, 6 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..89898afe8 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,11 @@ console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable // Create a variable to store the ext part of the variable -const dir = ; -const ext = ; +const dir = filePath.slice(0, lastSlashIndex + 1); +const lastSlDotIndex = filePath.lastIndexOf("."); +const ext = filePath.slice(lastSlDotIndex); + +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 a1bcfd7854269900975a2e8bb17df2e81f1c0a11 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Tue, 21 Oct 2025 12:10:43 +0100 Subject: [PATCH 03/10] 4th completed and explained. --- Sprint-1/1-key-exercises/4-random.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..c7eec5b7f 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,3 +7,12 @@ 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); + +// this will make a random number between 1-100. Math.random will give us a number between 0-1 (both ends included). +// (maximum - minimum + 1): this is equal to 100-1+1=100 in this example. +// (Math.random() * (maximum - minimum + 1)): this will multiply the random number which is between 0-1 by 100 so we have a number. +// Math.floor: this will round the number to the nearest lower whole number. +// + minimum: will add 1 (the defined minimum) to the number so it never be below 1. +// so we end up with a random number between 1-100 \ No newline at end of file From 8ddf08fb04e555af9543f693f1e18d489be1b30a Mon Sep 17 00:00:00 2001 From: Payman IB Date: Tue, 21 Oct 2025 13:06:20 +0100 Subject: [PATCH 04/10] Errors are fixed and explained for exercise 2. --- Sprint-1/2-mandatory-errors/0.js | 6 ++++-- Sprint-1/2-mandatory-errors/1.js | 4 +++- Sprint-1/2-mandatory-errors/2.js | 4 +++- Sprint-1/2-mandatory-errors/3.js | 10 +++++++++- Sprint-1/2-mandatory-errors/4.js | 9 +++++++-- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..7a1b95df3 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,4 @@ -This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +// This is just an instruction for the first activity - but it is just for human consumption +// We don't want the computer to run these 2 lines - how can we solve this problem? + +// we need to add double "//" at the start of the line so computer will ignore this line. \ 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..0b227e7ab 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,6 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +// const age = 33; age should be defined as let so it can get different values. +let age = 33 age = age + 1; +console.log(age); \ 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 e09b89831..f172f4a91 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 ? +// any variable must be defined first and then can be used. -console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); +// const cityOfBirth = "Bolton"; => Wrong place! diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..3ab022d80 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,6 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); + +const last4Digits = cardNumber.toString().slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,3 +8,10 @@ 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 + + + +//.Slice() is for strings but here we have 1 number here. so we need to make that number a string by putting it in a "". or using .toString() to change any input to string type. + + +console.log(last4Digits); \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..a1ee24b93 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,7 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +//const 12HourClockTime = "20:53"; +//const 24hourClockTime = "08:53"; + +// An identifier or keyword cannot immediately follow a numeric literal. + +const ClockTime24Hour = "20:53"; +const ClockTime12hour = "08:53"; \ No newline at end of file From 74687a6020be02645528c2d88d7a50c8c7cd9a90 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Tue, 21 Oct 2025 14:02:11 +0100 Subject: [PATCH 05/10] 1-percentage-change completed => questions are answered. --- .../1-percentage-change.js | 23 ++++++++++++++++++- 1 file changed, 22 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..79845cfcf 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -11,12 +11,33 @@ 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 +// a) How many function calls are there in this file? Write down all the lines where a function call is made + +// lines 4,5,7,8 +// the following 4 lines are functions as they are manipulating the data. +//carPrice = Number(carPrice.replaceAll(",", "")); +//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ,"")); +//const priceDifference = carPrice - priceAfterOneYear; +//const percentageChange = (priceDifference / carPrice) * 100; // 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? +// line 5 +// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); the error is a missing "," in ...replaceAll("," , "")). with out a "," the " "" are not separated and computer read them together. + // c) Identify all the lines that are variable reassignment statements +// lines 4,5 +//carPrice = Number(carPrice.replaceAll(",", "")); +//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); + +//carPrice = Number(carPrice.replaceAll(",", "")); +//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); + + // d) Identify all the lines that are variable declarations +// lines 1,2,7,8 + // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +// it replace the "," with "" which means omitting the "," so we have whole number that computer can work with it. From 8257fa0355b1d0db97afd690081078f8135a7b8e Mon Sep 17 00:00:00 2001 From: Payman IB Date: Tue, 21 Oct 2025 19:00:37 +0100 Subject: [PATCH 06/10] sprint 1- mandatory-interpret 1 & 2 completed --- .../3-mandatory-interpret/2-time-format.js | 13 +++++++++ Sprint-1/3-mandatory-interpret/3-to-pounds.js | 29 +++++++++---------- 2 files changed, 27 insertions(+), 15 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..2a9830b51 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -13,13 +13,26 @@ console.log(result); // a) How many variable declarations are there in this program? +6 + // b) How many function calls are there? +5 + // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +// % is the remainder. that line of code divides the total seconds number by 60 and gives us the remaining seconds. + // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// in this line, totalMinutes of the move calculated. the remainder will be deducted and the rest of the second divided by 60 gives us the total minutes number. + + // e) What do you think the variable result represents? Can you think of a better name for this variable? +// it represents the move length in hour, minutes and seconds. and it would be better understood as duration. + // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer + +// yes as long as it receives the total seconds as a whole number it works fine. \ 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 60c9ace69..3d79aefbd 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -1,20 +1,9 @@ const penceString = "399p"; - -const penceStringWithoutTrailingP = penceString.substring( - 0, - penceString.length - 1 -); - +const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1); const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); -const pounds = paddedPenceNumberString.substring( - 0, - paddedPenceNumberString.length - 2 -); - -const pence = paddedPenceNumberString - .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); - +const pounds = paddedPenceNumberString.substring( 0 , paddedPenceNumberString.length - 2); +const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2) +.padEnd(2, "0"); console.log(`£${pounds}.${pence}`); // This program takes a string representing a price in pence @@ -25,3 +14,13 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" +// 2. const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1): creates a new string with the last character removed by taking a substring from index 0 up to +// penceString.length - 1, it removes the trailing "p" so we are left with the numeric pence portion as a string. +// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): ensures the numeric string has at least 3 characters by adding leading zeros if required. +// padStart(3, "0") will left-pad with "0" until the length is at least 3, so the code expects to split the string into ...pounds and last two digits = pence. +// By guaranteeing at least 3 characters, the substring operations that follow always have at least one digit for pounds and two for pence. +// 4. const pounds = paddedPenceNumberString.substring( 0 , paddedPenceNumberString.length - 2): takes the substring from the start up to the character two from the end. +// That is, everything except the last two characters. as the last two characters represent pence; everything before that is pounds. Splitting this way converts a string of +// pure pence into pounds and pence parts. +// 5. substring(paddedPenceNumberString.length - 2): takes the last two characters (the pence portion). +// 6. .padEnd(2, "0"): would add trailing zeros to make sure the pence string is at least 2 characters long. \ No newline at end of file From 2a33fa1737340de469f1b5af7d5205890e7d939a Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sun, 26 Oct 2025 13:23:03 +0000 Subject: [PATCH 07/10] Chrome .md completed --- Sprint-1/4-stretch-explore/chrome.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feaf..1a7239f5d 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -11,8 +11,10 @@ In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? +"Hello world!" will be printed in a pop up box. 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? +A pop up window with the question and a place to input answer is opening. What is the return value of `prompt`? +The input value will be returned by prompt() and stored in the variable myName. \ No newline at end of file From 870693a912658e4e80952610be5293f2358ae450 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sun, 26 Oct 2025 13:42:01 +0000 Subject: [PATCH 08/10] Sprint-1/Objects.md completed --- Sprint-1/4-stretch-explore/objects.md | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56..f86e81584 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -1,16 +1,22 @@ ## Objects -In this activity, we'll explore some additional concepts that you'll encounter in more depth later on in the course. +//In this activity, we'll explore some additional concepts that you'll encounter in more depth later on in the course. -Open the Chrome devtools Console, type in `console.log` and then hit enter +//Open the Chrome devtools Console, type in `console.log` and then hit enter -What output do you get? +// What output do you get? +// ƒ (){for(var o=arguments.length,u=new Array(o),l=0;lt.toString())).splice(1),c=("assert"===… -Now enter just `console` in the Console, what output do you get back? +//Now enter just `console` in the Console, what output do you get back? +// console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} -Try also entering `typeof console` +//Try also entering `typeof console` +//Answer the following questions: +//What does `console` store? +//The console in JavaScript doesn’t store the program’s variables or data — instead, it’s an object provided by the browser (or Node.js) that contains a set of methods for +//logging information, debugging, and interacting with the JavaScript environment. -Answer the following questions: - -What does `console` store? -What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +//What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +//In both cases, console is an object, and log or assert are properties (specifically, methods) of that object. The dot (.) is called the dot notation operator or member +//access operator. It is used in JavaScript (and many other languages) to access a property or method that belongs to an object. From f8a651069829bc354815cf90d9e245ee1285abe0 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Wed, 29 Oct 2025 16:10:04 +0000 Subject: [PATCH 09/10] Lines 26 & 43 updated. --- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index 79845cfcf..d9bd870d3 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -23,7 +23,8 @@ 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? // line 5 -// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); the error is a missing "," in ...replaceAll("," , "")). with out a "," the " "" are not separated and computer read them together. +// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); the error is a missing comma between the two arguments in the .replaceAll() function call. Without the comma, +// the two string arguments "," and "" are not separated, so the computer reads them together as one argument. // c) Identify all the lines that are variable reassignment statements @@ -40,4 +41,4 @@ console.log(`The percentage change is ${percentageChange}`); // lines 1,2,7,8 // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? -// it replace the "," with "" which means omitting the "," so we have whole number that computer can work with it. +// It replace the "," with "" which means omitting the "," and add nothing so we have whole number form that computer can work with it. From bc21da92c86a4e6276bd11274fe794e4201eb2f3 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Wed, 29 Oct 2025 16:17:12 +0000 Subject: [PATCH 10/10] Line 20, error fixed --- 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 2a9830b51..9fee4fda1 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -17,7 +17,7 @@ console.log(result); // b) How many function calls are there? -5 +// 1 : 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