From b52ce708038d9dfc2c945aa530ffb7687351240d Mon Sep 17 00:00:00 2001 From: Seti Mussa Date: Mon, 2 Mar 2026 15:11:13 +0000 Subject: [PATCH 1/3] Key -exercise 1 done. --- Sprint-1/1-key-exercises/1-count.js | 3 +-- Sprint-1/1-key-exercises/2-initials.js | 3 +-- Sprint-1/1-key-exercises/3-paths.js | 1 - 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6e..c7f4efc0a7 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -2,5 +2,4 @@ let count = 0; count = count + 1; -// Line 1 is a variable declaration, creating the count variable with an initial value of 0 -// Describe what line 3 is doing, in particular focus on what = is doing +// Line 1 makes a variable called count and gives the value 0. Line 3 ads 1 to the value of count. So after line 3, count has the value 1. If we were to run line 3 again, count would have the value 2. If we were to run line 3 again, count would have the value 3. And so on. Each time we run line 3, we add 1 to the value of count. \ 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 47561f6175..8040083829 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,6 @@ let lastName = "Johnson"; // Declare a variable called initials that stores the first character of each string. // This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. -let initials = ``; +let initials = firstName[0] + middleName[0] + lastName[0]; -// https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28e..c192d73941 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -20,4 +20,3 @@ 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 From a6db6fb3890b57d6ddfbcff37ebe488e150223a5 Mon Sep 17 00:00:00 2001 From: Seti Mussa Date: Wed, 4 Mar 2026 15:25:19 +0000 Subject: [PATCH 2/3] Done Sprint 1 --- Sprint-1/1-key-exercises/1-count.js | 3 ++- Sprint-1/1-key-exercises/3-paths.js | 6 +++-- Sprint-1/1-key-exercises/4-random.js | 3 +++ Sprint-1/2-mandatory-errors/0.js | 6 ++++- Sprint-1/2-mandatory-errors/1.js | 5 ++++ Sprint-1/2-mandatory-errors/2.js | 5 ++++ Sprint-1/2-mandatory-errors/3.js | 6 +++++ Sprint-1/2-mandatory-errors/4.js | 8 +++++- .../1-percentage-change.js | 27 ++++++++++++++++--- .../3-mandatory-interpret/2-time-format.js | 21 +++++++++++++++ Sprint-1/3-mandatory-interpret/3-to-pounds.js | 5 ++++ Sprint-1/4-stretch-explore/chrome.md | 6 +++++ Sprint-1/4-stretch-explore/objects.md | 13 ++++++++- 13 files changed, 105 insertions(+), 9 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index c7f4efc0a7..9ae07a1b2b 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -2,4 +2,5 @@ let count = 0; count = count + 1; -// Line 1 makes a variable called count and gives the value 0. Line 3 ads 1 to the value of count. So after line 3, count has the value 1. If we were to run line 3 again, count would have the value 2. If we were to run line 3 again, count would have the value 3. And so on. Each time we run line 3, we add 1 to the value of count. \ No newline at end of file +// line 1 makes box called count and puts 0 inside it. +// line 3 adds 1 to count. diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index c192d73941..977c92eb67 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,6 +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 lastDotIndex = base.lastIndexOf("."); +const ext = filePath.slice(lastDotIndex + 1); +// https://www.google.com/search?q=slice+mdn \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aabb..4abd34976a 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,3 +7,6 @@ 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 + +//num is random whole number between 1 and 100. +//each time the program runs, it creates a different number in that range. diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f7..71d94c9963 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 +We don't want the computer to run these 2 lines - how can we solve this problem? + + +// We can add // at the start of the lines to turn them into comments. +// The computer ignores comments, so it will not run them. \ 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 7a43cbea76..374c804246 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -2,3 +2,8 @@ const age = 33; age = age + 1; + +// The error happens because age was declared using const. +// const variable canot be changed. +// We trying to change age ,so casue error. +// It should use let instead. diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831d..dbcdc76f0e 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -3,3 +3,8 @@ console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; + +// The error happens because cityOfBirth is used before it is declared. +// Const variable cannot be used before declaration. +// Move the variable delaration before the console.log line. + diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884db..2a6d3cb7bd 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -7,3 +7,9 @@ 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 + + +// The code will not work because slice() cannot be used on numbers. +// Slice() only works on strings or arrays. +//We need to convert the number to string first +const last4Digits = cardNumber.to String().slice(-4); \ 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 21dad8c5d1..7e64f0a8a2 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,8 @@ const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const 24hourClockTime = "08:53"; + +// Variables names cannot start with a number. +// Rename the variables so they start with a letter. +const hour12ClockTime = "20:35"; +const hour24ClockTime = "08:35"; + diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e18..6b37e53ab3 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -4,19 +4,40 @@ let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); -const priceDifference = carPrice - priceAfterOneYear; -const percentageChange = (priceDifference / carPrice) * 100; +const PriceDifference = carPrice - priceAfterOneYear; +const PercentageChange = (PriceDifference / carPrice) * 100; -console.log(`The percentage change is ${percentageChange}`); +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 +// there are 4 function calls in this file. +carPrice.replaceAll(",", "") +priceAfterOneYear.replaceAll(",", "") +Number(carPrice.replaceAll(",", "")) +Number(priceAfterOneYear.replaceAll(",", "")) + // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? +// the error is comin from this line + +priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +// the error happens becuae there is missing comma inside reaplaceAll(). +//The correct line should be +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); // c) Identify all the lines that are variable reassignment statements +// This lines +carPrice = Number(carPrice.reaplaceAll(",", "")); // d) Identify all the lines that are variable declarations +let carPrice = 10,000"; +let priceAfterOneYear = "8,543"; +const priceDifference = carPrice - priceAfterOneyear; +const percentageChange = (priceDifference / carPrice) * 100; + // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +Number(carPrice.replaceAll(",", "")) +// It removes commas from the number string and converts the results into a real number so calculation can be done. \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d2395587..b7e5b1735c 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -12,14 +12,35 @@ 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 in this program. + movieLength +remainingSeconds +totalMinutes +remainingMinutes +totalHours +result // b) How many function calls are there? +There is 1 function call in this program. + console.log(result) +// The function call is on line 10, where we are calling the console.log function to print the value of result to the console. // 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 after dividing movielenth by 60. It gives us the number of seconds that are left over after we have taken out all the whole minutes from the movie length + + + // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// first remove the extra seconds. +// then divide by 60 to get the total number of minutes in the movie length. // e) What do you think the variable result represents? Can you think of a better name for this variable? +// The variable result represents the formatted time in hours:minutes:seconds format. +// A better name for this varibale could be formattedTime. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// no, this code will not work good for all values of movielength. +// it will only right for postitive whole number of seconds. +// if movieLength is nagatuve or not a whole number, the result will not be right. \ 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 60c9ace69a..38a79ca301 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,8 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" +// 2.Removes the "p" at the end, leaving "399". +// 3. Makes sure the number has at least 3 digits . +// 4, takes the first part as pounds. +// 5. Takes the last two digits as pence. +// 6. Prints the price in punds format ( for example, £3.99). \ No newline at end of file diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feafe..465614f06d 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -11,8 +11,14 @@ In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? +// It shows a popup message in the browser with the "Hello + world!". + // Then I must clicks ok to close it. 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? +//Its shows a popup with text box where user can type something. What is the return value of `prompt`? +//It returns the text the user types. +//If the user clicks Cancel, it returns null. \ No newline at end of file diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56a..e5bb0b7098 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -5,12 +5,23 @@ 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? +// It shows that consel.log is function. Now enter just `console` in the Console, what output do you get back? +// shows an object with many function inside it (like,error) Try also entering `typeof console` +//It resturn objects. Answer the following questions: What does `console` store? -What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +// conseole store an object. +// This object contains many functions used for priniting message and debugging. + +What does the syntax `console.log` or `console.assert` mean? +// It means we ar using something inside the consel object. + In particular, what does the `.` mean? +// The dots is used to access something inside an objects. +//For example ,console.log means: +// Go inside the console object and use the log function. \ No newline at end of file From dd9daab794cc8238081397da3e3d0049b856b4c1 Mon Sep 17 00:00:00 2001 From: Seti Mussa Date: Fri, 6 Mar 2026 15:06:31 +0000 Subject: [PATCH 3/3] I have correct all the mistakes --- Sprint-1/1-key-exercises/1-count.js | 2 ++ Sprint-1/2-mandatory-errors/3.js | 2 +- .../3-mandatory-interpret/1-percentage-change.js | 12 ++++++------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 9ae07a1b2b..516b14b47d 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,5 @@ count = count + 1; // line 1 makes box called count and puts 0 inside it. // line 3 adds 1 to count. +//Line 3 is an increment operation because it increases the value of the variable count by 1. + diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index 2a6d3cb7bd..9b9c91742c 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -12,4 +12,4 @@ const last4Digits = cardNumber.slice(-4); // The code will not work because slice() cannot be used on numbers. // Slice() only works on strings or arrays. //We need to convert the number to string first -const last4Digits = cardNumber.to String().slice(-4); \ No newline at end of file +const last4Digits = cardNumber.toString().slice(-4); \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index 6b37e53ab3..2d0c3e6c06 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -2,12 +2,12 @@ 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; +const priceDifference = carPrice - priceAfterOneYear; +const percentageChange = (priceDifference / carPrice) * 100; -console.log(`The percentage change is ${PercentageChange}`); +console.log(`The percentage change is ${percentageChange}`); // Read the code and then answer the questions below @@ -23,8 +23,8 @@ Number(priceAfterOneYear.replaceAll(",", "")) // the error is comin from this line priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); -// the error happens becuae there is missing comma inside reaplaceAll(). -//The correct line should be +// The error happens because a comma is missing between the arguments in the replaceAll() function. +// The correct line should be priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); // c) Identify all the lines that are variable reassignment statements