From 4537db55b856ac45b92a8de39f290f020edb26b7 Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Sat, 7 Jun 2025 12:36:32 +0100 Subject: [PATCH 01/23] tried to explain variable redeclaration --- 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..01ba66b16 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 + +// We are updating the previous value of count to a new value. The = operator assigns a new value +// to the variable, meaning the data stored in memory is being changed. \ No newline at end of file From 2c8408a7939592f9ac050043dde40fcf396b71bb Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Sat, 7 Jun 2025 12:37:48 +0100 Subject: [PATCH 02/23] leaned how to use string formatting --- 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 47561f617..db7d556f7 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]}`; // https://www.google.com/search?q=get+first+character+of+string+mdn +console.log(initials); \ No newline at end of file From e07fba5df3357130fc49e13ade29da222a4663e5 Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Sat, 7 Jun 2025 12:41:05 +0100 Subject: [PATCH 03/23] learned slice,lastIndexOf and how can we use them together for slice --- Sprint-1/1-key-exercises/3-paths.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28..ce44994db 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -14,10 +14,17 @@ 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); +console.log(`The div part of ${filePath} is ${dir}`); + + // Create a variable to store the ext part of the variable +const lastDoteIndex = filePath.lastIndexOf("."); +const ext = filePath.slice(lastDoteIndex); +console.log(`The ext part of ${filePath} is ${ext}`); -const dir = ; -const ext = ; +// https://www.google.com/search?q=slice+mdn -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +console.log(lastSlashIndex); \ No newline at end of file From b5673e8bb2815c64a65d15eaffeaf18ecdb3f53a Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Sat, 7 Jun 2025 12:41:38 +0100 Subject: [PATCH 04/23] explained num represents --- Sprint-1/1-key-exercises/4-random.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..e869f726b 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -3,7 +3,22 @@ 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 // Try logging the value of num and running the program several times to build an idea of what the program is doing + + +// order of math calculation - () > ** > * / % > + - (Parentheses first, then Exponentiation +// (right to left), then Multiplication/Division/Modulo (left to right), then Addition/Subtraction +// (left to right)). + +//Math.floor - returns the value of x rounded down to its nearest integer +//Math.random - returns a random number + +// First, the innermost parentheses are evaluated: (maximum - minimum + 1). +// Then, the result is multiplied by the random number generated by the Math object. +// Math.floor rounds the result down to the nearest integer. +// Finally, the value is added to the minimum. \ No newline at end of file From f946b02cf2178b76a014ccf3731b5de37def6440 Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Sat, 7 Jun 2025 13:34:09 +0100 Subject: [PATCH 05/23] make a comment --- Sprint-1/2-mandatory-errors/0.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..3e6a16ca1 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 sole this by witting these two as comments \ No newline at end of file From e7ba13d06441b5da1c556201a1fa5b694d3eda14 Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Sat, 7 Jun 2025 13:34:50 +0100 Subject: [PATCH 06/23] understanding const and let --- Sprint-1/2-mandatory-errors/1.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..953c99674 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; +let age = 33; age = age + 1; + +// we have to use let as it allows the value to be reassign \ No newline at end of file From 0def05a9a3be087dd15084794069957e5639bca0 Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Sat, 7 Jun 2025 13:35:47 +0100 Subject: [PATCH 07/23] understating how does system reads the coder --- Sprint-1/2-mandatory-errors/2.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..97f2edd8d 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,15 @@ // 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}`); +// the system reads the code top to bottom and because the variable has been create/define before +// the consol.log it can not recognize the variable + +//Wrong +//console.log(`I was born in ${cityOfBirth}`); +//const cityOfBirth = "Bolton"; + +//correct const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); + + From 6421e9f54286ec36348c78652031f9ab2d3a3cab Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Sat, 7 Jun 2025 13:51:45 +0100 Subject: [PATCH 08/23] string method --- Sprint-1/2-mandatory-errors/3.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..7ad5dfc1a 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -7,3 +7,6 @@ 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 - slice is for string not integer + From 87d44ebb5556ac69711f74014513b60f05b32087 Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Sat, 7 Jun 2025 15:09:52 +0100 Subject: [PATCH 09/23] string methods --- Sprint-1/2-mandatory-errors/3.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index 7ad5dfc1a..85ef3d2a2 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -8,5 +8,6 @@ const last4Digits = cardNumber.slice(-4); // 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 - slice is for string not integer +//prediction - slice() is a string method +console.log(last4Digits); \ No newline at end of file From 259306e998718302ef0abdb2cd5abef8bf17c396 Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Sat, 7 Jun 2025 15:11:03 +0100 Subject: [PATCH 10/23] learn about Variable Naming Rules --- Sprint-1/2-mandatory-errors/4.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..e5bddfb48 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,15 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const HourClockTime24 = "20:53"; +const hourClockTime12 = "08:53"; + +// Go Variable Naming Rules +// A variable can have a short name (like x and y) or a more descriptive name (age, price, carname, etc.). + +// Go variable naming rules: + +// A variable name must start with a letter or an underscore character (_) +// A variable name cannot start with a digit +// A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _ ) +// Variable names are case-sensitive (age, Age and AGE are three different variables) +// There is no limit on the length of the variable name +// A variable name cannot contain spaces +// The variable name cannot be any Go keywords \ No newline at end of file From be72b0dd578fe1ade1b8187a958189d9f10f23b6 Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Sat, 7 Jun 2025 19:29:10 +0100 Subject: [PATCH 11/23] answered the questions --- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 10 +++++++++- 1 file changed, 9 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..0c5498b6f 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; @@ -12,11 +12,19 @@ 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 +// 4(.replaceAll), 5(.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? +// from line :5 +// fix: add , - priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); // c) Identify all the lines that are variable reassignment statements +// line 4 , 5 // d) Identify all the lines that are variable declarations +// line : 1 , 2 // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +// method replaceAll is changing a specific character and replace it with the one we asked for. +// function number which changes a string number value to integers. +// purpose : is to have a integer instead of a string From b47e4999f21eb827ae8ac6c65021d6b7dc74fb88 Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Sat, 7 Jun 2025 19:32:52 +0100 Subject: [PATCH 12/23] answered the questions --- Sprint-1/3-mandatory-interpret/2-time-format.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 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 47d239558..bcfd79eac 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -7,19 +7,31 @@ const remainingMinutes = totalMinutes % 60; const totalHours = (totalMinutes - remainingMinutes) / 60; const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; -console.log(result); +console.log(totalMinutes); // 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? +// 6 // b) How many function calls are there? +// 1 // 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 (modulo) returns the remainder of a division. +// In this case, it returns how many seconds are left after dividing the total seconds by 60. +// For example, 8784 % 60 = 24 — so 24 seconds remain. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// we are calculating the total minutes. +// we subtract movieLength by remainingSeconds because remaining seconds don't add up to a full min. +// convert to minute by dividing by 60. // e) What do you think the variable result represents? Can you think of a better name for this variable? +// The variable `result` represents the movie's length in a time format: `HH:MM:SS`. +// string format // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// Yes, the code works for all non-negative values of `movieLength`, including 0. +// However, for values less than 60, it will return 0 hours and 0 minutes \ No newline at end of file From cf581dd1366323184a8794db8908438f38060e57 Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Sat, 7 Jun 2025 19:33:40 +0100 Subject: [PATCH 13/23] explained the code line by line --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 21 ++++++++++++++++++- 1 file changed, 20 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..f5067030b 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -24,4 +24,23 @@ 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": initializes a string variable with the value "399p" + +// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1); +// .substring - selects a section between the given indexes in a string -> "399", by doing this we remove the "p" + +// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +// The padStart() method pads penceStringWithoutTrailingP with another string (multiple times) until it reaches a given length 3. +// id we have a one digit number it adds two "004" but if the number is 3 digits will keep it as it is "399" + +// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2); +// Extracts the pound portion, which is the first part of the 3-digit string -> "3" + +// 5. const pence = paddedPenceNumberString +// .substring(paddedPenceNumberString.length - 2) +// .padEnd(2, "0"); +// it is two separate parts +// first - with substring method we select the two last digits +// second - ensures that if somehow only one digit is returned it’s padded to two characters by adding a "0" to the end. + +// 6. Displays the formatted price in British pounds -> £3.99 or £0.05 \ No newline at end of file From 3999f6261f83df0b78ed29a0fdb37e7d757e9b48 Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Sat, 7 Jun 2025 20:25:29 +0100 Subject: [PATCH 14/23] learned what is v8 and node.js --- Sprint-1/4-stretch-explore/chrome.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feaf..4d2132653 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -15,4 +15,7 @@ What effect does calling the `alert` function have? 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? +browser displays a popup dialog box + What is the return value of `prompt`? +is a string containing what they typed. From d314a9571ce835d53978d56eb8324c46d61aae6d Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Sat, 7 Jun 2025 20:27:39 +0100 Subject: [PATCH 15/23] a short view of object oriented languages. what is a object and how can we access methods --- Sprint-1/4-stretch-explore/objects.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56..de828f992 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -5,12 +5,30 @@ 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? +ƒ log() { [native code] } + Now enter just `console` in the Console, what output do you get back? +console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} Try also entering `typeof console` +typeof(console); +'object' Answer the following questions: What does `console` store? +console is a built-in JavaScript object provided by browsers (like Chrome, Firefox, etc.). It stores a collection of functions that help developers log, debug, and inspect values during runtime. +It doesn’t store data like a variable; instead, it holds methods (a.k.a. functions) like: +console.log() – print to the console +console.error() – print errors +console.warn() – print warnings +console.assert() – test if an expression is true + What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +- `console.log` or `console.assert` +These are method calls on the console object. +You're telling JavaScript: "Use the log or assert method that belongs to the console object." +- the `.` mean +The dot (.) is the member access operator in JavaScript. +It accesses a property or method of an object \ No newline at end of file From 078e27969a479947fa2902768d6669fc7eb2dcd6 Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Thu, 19 Jun 2025 11:49:05 +0100 Subject: [PATCH 16/23] cleaned up the code style --- Sprint-1/1-key-exercises/3-paths.js | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ce44994db..c2906650c 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -9,22 +9,13 @@ // (All spaces in the "" line should be ignored. They are purely for formatting.) -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}`); +const lastDotIndex = filePath.lastIndexOf("."); +const base = filePath.slice(lastSlashIndex + 1); // file.txt +const dir = filePath.slice(0, lastSlashIndex); // /Users/mitch/cyf/Module-JS1/week-1/interpret +const ext = filePath.slice(lastDotIndex); // .txt -// Create a variable to store the dir part of the filePath variable -const dir = filePath.slice(0 ,lastSlashIndex + 1); -console.log(`The div part of ${filePath} is ${dir}`); - - -// Create a variable to store the ext part of the variable -const lastDoteIndex = filePath.lastIndexOf("."); -const ext = filePath.slice(lastDoteIndex); -console.log(`The ext part of ${filePath} is ${ext}`); - -// https://www.google.com/search?q=slice+mdn - -console.log(lastSlashIndex); \ No newline at end of file +console.log(`Base part of path: ${base}`); +console.log(`Dir part of path: ${dir}`); +console.log(`Ext part of path: ${ext}`); \ No newline at end of file From 54f716e8d531b8ef83b4ade30455b763443786ed Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Thu, 19 Jun 2025 13:19:31 +0100 Subject: [PATCH 17/23] describe output, purpose --- Sprint-1/1-key-exercises/4-random.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index e869f726b..ebed977d1 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -21,4 +21,7 @@ console.log(num); // First, the innermost parentheses are evaluated: (maximum - minimum + 1). // Then, the result is multiplied by the random number generated by the Math object. // Math.floor rounds the result down to the nearest integer. -// Finally, the value is added to the minimum. \ No newline at end of file +// Finally, the value is added to the minimum. + +// the purpose - To generate a random whole number between minimum and maximum, inclusive. +// output - It will be a random integer between 1 and 100. \ No newline at end of file From f7e6a171bb594d5c2d554f38163bcd6a294880a5 Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Thu, 19 Jun 2025 13:21:18 +0100 Subject: [PATCH 18/23] change the number to a string --- Sprint-1/2-mandatory-errors/3.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index 85ef3d2a2..9cbb1e71b 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,4 +1,4 @@ -const cardNumber = 4533787178994213; +const cardNumber = "4533787178994213"; const last4Digits = cardNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber From 72c375fdbe65f61af98d33248715d02deb5c321f Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Thu, 19 Jun 2025 13:23:18 +0100 Subject: [PATCH 19/23] answered all the questions --- .../1-percentage-change.js | 27 +++++++++++++++++-- 1 file changed, 25 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 0c5498b6f..321d928a6 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -12,19 +12,42 @@ 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 -// 4(.replaceAll), 5(.replaceAll) +// Function calls: +// Line 4 - .replaceAll, Number +// Line 5 - .replaceAll, 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? // from line :5 // fix: add , - priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); +// Why is the original line causing an error? +// We were trying to subtract two string values like "30000" - "24000" but +// In JavaScript, strings with commas (like "24,000") can’t be parsed directly to numbers +// So this fails + + // c) Identify all the lines that are variable reassignment statements // line 4 , 5 + + // d) Identify all the lines that are variable declarations -// line : 1 , 2 +// lines : 1 , 2 , 7 , 8 +// Line 1: let carPrice +// Line 2: let priceAfterOneYear +// Line 6: const priceDifference +// Line 7: const percentageChange + + // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? // method replaceAll is changing a specific character and replace it with the one we asked for. // function number which changes a string number value to integers. // purpose : is to have a integer instead of a string + +// explain why we want to convert it into an integer? +// We use Number(carPrice.replaceAll(",", "")) to convert a formatted string into a real number, +// so we can do mathematical calculations on it. \ No newline at end of file From 1d85b487f7ca00d1093de8e71e568b23a7dfb2b8 Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Thu, 19 Jun 2025 13:24:57 +0100 Subject: [PATCH 20/23] changed the variable called result --- Sprint-1/3-mandatory-interpret/2-time-format.js | 4 ++-- 1 file changed, 2 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 bcfd79eac..b738070b5 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -6,7 +6,7 @@ const totalMinutes = (movieLength - remainingSeconds) / 60; const remainingMinutes = totalMinutes % 60; const totalHours = (totalMinutes - remainingMinutes) / 60; -const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; +const formattedTime = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; console.log(totalMinutes); // For the piece of code above, read the code and then answer the following questions @@ -31,7 +31,7 @@ console.log(totalMinutes); // e) What do you think the variable result represents? Can you think of a better name for this variable? // The variable `result` represents the movie's length in a time format: `HH:MM:SS`. // string format - +// better name can be `formattedTime` or `HHMMSS` // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer // Yes, the code works for all non-negative values of `movieLength`, including 0. // However, for values less than 60, it will return 0 hours and 0 minutes \ No newline at end of file From 73cc423bdca08b8461ec0e31078233100587db3c Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Thu, 19 Jun 2025 13:26:04 +0100 Subject: [PATCH 21/23] try the alert function, possible values we get from prompt --- Sprint-1/4-stretch-explore/chrome.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index 4d2132653..3c3e7c509 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -11,11 +11,18 @@ In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? + -It causes the browser to display a modal popup box with the message "Hello world!" + -It blocks interaction with the page until the user clicks "OK" + -It returns undefined — the purpose is only to notify, not to receive input. 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`. +const myName = prompt("What is your name?"); + What effect does calling the `prompt` function have? browser displays a popup dialog box What is the return value of `prompt`? -is a string containing what they typed. + A string - if the user types something and clicks OK + An empty string ("") - if they click OK but type nothing + null - if the user clicks Cancel From 77b600c55188f9d02dc5b14397baf8578595a453 Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Fri, 20 Jun 2025 10:50:30 +0100 Subject: [PATCH 22/23] fixed the code --- Sprint-1/2-mandatory-errors/3.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index 9cbb1e71b..4d69e8741 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,4 +1,4 @@ -const cardNumber = "4533787178994213"; +let cardNumber = "4533787178994213"; const last4Digits = cardNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber From 637cd50cc745b3ceae8101b7f4678e3c851532f9 Mon Sep 17 00:00:00 2001 From: Reza Jahanimir Date: Sun, 22 Jun 2025 13:35:08 +0100 Subject: [PATCH 23/23] use a toString()method --- Sprint-1/2-mandatory-errors/3.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index 4d69e8741..8094a71e1 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,13 +1,22 @@ -let cardNumber = "4533787178994213"; -const last4Digits = cardNumber.slice(-4); +// result as a string +let cardNumber = 4533787178994213; +const last4Digits = cardNumber.toString().slice(-4); +console.log(last4Digits); // Output: "4213" -// 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 -//prediction - slice() is a string method +// result as a number +const last4DigitsNum = Number(cardNumber.toString().slice(-4)); +console.log(last4DigitsNum); // Output: 4213 -console.log(last4Digits); \ No newline at end of file + +// the function your asked return string +function last4DigitsStr(cardNumber) { + const last4Digs= cardNumber.toString().slice(-4); + return last4Digs; +} + +// the function your asked return number +function last4DigitsNum(number) { + const last4Digs= Number(number.toString().slice(-4)); + return last4Digs; +} \ No newline at end of file