From 7b4bf3563f87e0d885f7ac88ad15af58709f2dd9 Mon Sep 17 00:00:00 2001 From: khalil-ali1 Date: Fri, 18 Apr 2025 16:56:27 +0100 Subject: [PATCH 1/4] finish mandatory errors --- Sprint-1/2-mandatory-errors/0.js | 9 ++++++++- Sprint-1/2-mandatory-errors/1.js | 4 ++++ Sprint-1/2-mandatory-errors/2.js | 8 +++++++- Sprint-1/2-mandatory-errors/3.js | 7 ++++++- Sprint-1/2-mandatory-errors/4.js | 8 ++++++-- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..fc8ada888 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,9 @@ +/* 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? +*/ + +/* + * to add a comment you have two options : + 1- // add one line comment + 2- /*add multiline comment */ \ 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..a191bf80e 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -2,3 +2,7 @@ const age = 33; age = age + 1; + +/* +to define a variable with reassign feature you should use `let` instead of `const` +*/ \ 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..67fe88173 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,11 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? +const cityOfBirth = "Bolton"; console.log(`I was born in ${cityOfBirth}`); -const cityOfBirth = "Bolton"; + + +/*code is rendered line by line. + * so you should define the variable cityOfBirth first + * then you can use it + */ \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..4c8d21887 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 @@ -7,3 +7,8 @@ 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 +console.log(last4Digits) + +/*slice() is a function takes only string array as an argument. + * thats why we changed cardNumber + */ \ 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..17c5d2989 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,6 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const HourClockTime24 = "20:53"; +const hourClockTime12 = "08:53"; + +/*variables names can not start with a number. + * + */ \ No newline at end of file From 0249efe22110f3f63ce1bc72d811d0ab0e9bea33 Mon Sep 17 00:00:00 2001 From: khalil-ali1 Date: Fri, 18 Apr 2025 17:07:56 +0100 Subject: [PATCH 2/4] finish key-exercises --- Sprint-1/1-key-exercises/1-count.js | 5 +++++ Sprint-1/1-key-exercises/2-initials.js | 3 ++- Sprint-1/1-key-exercises/3-paths.js | 7 +++++-- Sprint-1/1-key-exercises/4-random.js | 13 +++++++++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..a56740c21 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,8 @@ 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 reassignment for the variable count. + we start from the right hand part so 0 + 1 = 1 + the " = " in line 3 means assigning the right hand part to the left hand var. + count = 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..0084d7abe 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]; +console.log(initials) // 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 ab90ebb28..b7c934891 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,10 @@ 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 = filePath.slice(lastSlashIndex + 5) + +console.log("dir :", dir) +console.log("ext :", ext) // 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 292f83aab..2d68819c4 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,3 +7,16 @@ 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 value is :", num) +/* +Math.random():returns a random number between n = [ 0 , 1 [ . +Math.floor() :returns the previous real number of a decimal number . +num = Math.floor (n*(100 - 1 + 1) + 1 ; +num = Math.floor (n*100 + 1) +num = Math.floor (100n + 1) + +num range between : [ 1 , 100 ] +num range between : [ minimum , maximum ] + +*/ \ No newline at end of file From 36aed183c7685a0920861e64d4972bdc94a89c13 Mon Sep 17 00:00:00 2001 From: khalil-ali1 Date: Fri, 18 Apr 2025 17:13:49 +0100 Subject: [PATCH 3/4] finish percentage-change --- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 8 +++++++- 1 file changed, 7 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..3822e0448 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; @@ -20,3 +20,9 @@ console.log(`The percentage change is ${percentageChange}`); // d) Identify all the lines that are variable declarations // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? + +// a) 3 times . lines (4,5,10) +// b) line 5 . syntax error in replaceAll function. add comma +// c) 4 , 5 lines +// d) 1 , 2 , 7 , 8 lines +// e) replace each "," in carPrice with nothing which means : delete each comma \ No newline at end of file From 9c999a998329b2b0dce736f696b44e49ac6b2633 Mon Sep 17 00:00:00 2001 From: khalil-ali1 Date: Fri, 18 Apr 2025 17:47:11 +0100 Subject: [PATCH 4/4] finish mandator interpret --- .../3-mandatory-interpret/2-time-format.js | 7 +++++++ Sprint-1/3-mandatory-interpret/3-to-pounds.js | 19 ++++++++----------- 2 files changed, 15 insertions(+), 11 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..2cdc284b0 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -23,3 +23,10 @@ console.log(result); // e) What do you think the variable result represents? Can you think of a better name for this variable? // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer + +// a) 6 times +// b) 1 time +// c) the reminder after applying division (movieLength / 60) which equals to 24 +// d) number of minutes in movieLength +// e) movieDuration +// f) yes it will work for all real positive values of movieLength \ 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..e9588020c 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -1,19 +1,11 @@ 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 pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2); -const pence = paddedPenceNumberString - .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); +const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); console.log(`£${pounds}.${pence}`); @@ -25,3 +17,8 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" +// 3. substring() : cuts a part of the whole string. in this line we remove "p" from penceString. +// 5. padStart() : add character to a string. in this line we check the string length is three,if not we add "0" to the start +// 6. accounts the number of pounds which is 3 +// 8. accounts the number of pounds which is 99. in this line we check the string length is two,if not we add "0" to the start +// 10. 3.99 \ No newline at end of file