From 12eb68244c3e930c90698b59b6d2f6d90ef0417c Mon Sep 17 00:00:00 2001 From: SuWebOnes Date: Tue, 24 Jun 2025 19:07:53 +0100 Subject: [PATCH 01/15] update: Add console log and comments to clarify count variable reassignment sprint -1 of 1-count.js --- Sprint-1/1-key-exercises/1-count.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..8717bea0c 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -2,5 +2,7 @@ let count = 0; count = count + 1; +console.log(count); // Output: 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 reassigning the count variable to a new value which is the current value increment by 1, "=" is assigning operator that assigning value of right side which mens count increment 1 to the left side value of count variable From b57e0f3643ad369fda100dc9b2b714245c151234 Mon Sep 17 00:00:00 2001 From: SuWebOnes Date: Tue, 24 Jun 2025 19:10:51 +0100 Subject: [PATCH 02/15] update: comments for clarity on initials variable creation in 2-initials.js --- Sprint-1/1-key-exercises/2-initials.js | 10 ++++++++-- 1 file changed, 8 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..1fbf1385e 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -1,11 +1,17 @@ let firstName = "Creola"; let middleName = "Katherine"; let lastName = "Johnson"; +// The code above declares these three variables: firstName, middleName, and lastName. +// Each variable is assigned a string value representing each element in the name. +// The task is to create a new variable take initials that combines the first character from each of these strings. +// The initials variable should contain the first letter of each name, resulting in the string "CKJ". // 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 = ``; - +initials = firstName[0] + middleName[0] + lastName[0]; +console.log(initials); // Output: CKJ +// The code above uses the bracket notation to access the first character of each string [0]. +// This is a common way to get the first character of a string in JavaScript. // https://www.google.com/search?q=get+first+character+of+string+mdn - From a7ffaa8fd85b0e32e1f654f82b125b0db2910ae8 Mon Sep 17 00:00:00 2001 From: SuWebOnes Date: Tue, 24 Jun 2025 19:11:59 +0100 Subject: [PATCH 03/15] update: Implement dir and ext variable assignments in 3-paths.js --- 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..c31eca467 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,14 @@ 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; +filePath.slice(0, lastSlashIndex); +const ext = filePath; +filePath + .slice(lastSlashIndex + 1) + .split(".") + .pop(); +// The code above uses the lastIndexOf method to find the position of the last slash in the filePath string. +// The slice method is then used to extract the base part of the filePath string, which is the part after the last slash. -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// https://www.google.com/search?q=slice+mdn From de6389dd139233f9a32eec63f404552738a78eea Mon Sep 17 00:00:00 2001 From: SuWebOnes Date: Tue, 24 Jun 2025 19:14:02 +0100 Subject: [PATCH 04/15] update: breaking down the expression and explain for clarity on random number generation in sprint -1 of 4-random.js --- Sprint-1/1-key-exercises/4-random.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..bace6513e 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,3 +7,10 @@ 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); +// Output: A random number between 1 and 100 (inclusive both 1 and 100) +//num is a random number generated between the minimum 1 and maximum values 100. +// The expression Math.random() generates a random floating-point number between [0,1). +// The expression (maximum - minimum + 1) calculates the range of numbers we want to generate, which is 100 - 1 + 1 = 100. +// The expression Math.floor() rounds down the result to the nearest whole number. +// Finally, we add the minimum value to ensure that the random number falls within the desired range. From 3425e3b016ffed8923cf69b992ec877fb5af8e97 Mon Sep 17 00:00:00 2001 From: SuWebOnes Date: Tue, 24 Jun 2025 19:15:10 +0100 Subject: [PATCH 05/15] update: Convert instructions to comments to prevent execution in sprint -1 of 0.js --- Sprint-1/2-mandatory-errors/0.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..044add7ac 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,2 @@ -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 fa0ebc794370c90fddc4f3a9c171f67b9ca601d7 Mon Sep 17 00:00:00 2001 From: SuWebOnes Date: Tue, 24 Jun 2025 19:16:23 +0100 Subject: [PATCH 06/15] update: Clarify age variable reassignment and correct declaration to 'let' in sprint -1 of 1.js --- Sprint-1/2-mandatory-errors/1.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..a1391a233 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -2,3 +2,6 @@ const age = 33; age = age + 1; +console.log(age); // Output: 34 +// The code above declares a variable age with an initial value of 33. +// It then reassigns the value of age by adding 1 to its current value, so the declaration must be using 'let' keyword. From 6697426021bff18274094ba1916bdc0f8154030e Mon Sep 17 00:00:00 2001 From: SuWebOnes Date: Tue, 24 Jun 2025 19:19:26 +0100 Subject: [PATCH 07/15] update: Fix variable declaration order and error explanation in sprint -1 of 2.js --- Sprint-1/2-mandatory-errors/2.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..b7e608bee 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 ? - -console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); + +//The error is that the variable cityOfBirth is being used before it has been declared.JavaScript executes code line by line from top to bottom, so you must declare and assign a value to the variable before using it. +// In JavaScript, variables declared with let or const are not hoisted, meaning they cannot be accessed before their declaration. From 61fd83816f2c0966e55a88fcaf0b55b5f6bc33f3 Mon Sep 17 00:00:00 2001 From: SuWebOnes Date: Tue, 24 Jun 2025 19:20:29 +0100 Subject: [PATCH 08/15] update: Add prediction and explanation for TypeError in card number slicing in sprint -1 of 3.js --- Sprint-1/2-mandatory-errors/3.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..8c4a85cd5 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,10 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +// Prediction: The code will not work because the `slice` method is being called on a number type (`cardNumber`), +// and the `slice` method is a string method. In JavaScript, numbers do not have a `slice` method. +// Running the code will likely result in a TypeError. + +const last4Digits = cardNumber.toString().slice(-4); // Convert cardNumber to a string first +console.log(`The last 4 digits of the card number are ${last4Digits}`); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working From 4a786db6579f338b53c98e792c717680b99d18f1 Mon Sep 17 00:00:00 2001 From: SuWebOnes Date: Tue, 24 Jun 2025 19:21:32 +0100 Subject: [PATCH 09/15] update: Add detailed comments and examples for time conversion functions in sprint -1 of 4.js --- Sprint-1/2-mandatory-errors/4.js | 39 ++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..1392058b1 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,37 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +// const 12HourClockTime = "20:53"; it is in 24 hour format +// const 24hourClockTime = "08:53"; it is in 12 hour format then we will write correctly +// const twelveHourClockTime = "08:53 PM"; // Example 12-hour format time +// const twentyFourHourClockTime = "20:53"; // Example 24-hour format time + +const twelveHourClockTime = "08:53 PM"; // Example 12-hour format time +const twentyFourHourClockTime = "20:53"; // Example 24-hour format time +function convertTo12HourClockTime(time24clock) { + let [hours, minutes] = time24clock.split(":").map(Number); + const modifier = hours >= 12 ? "PM" : "AM"; + + if (hours === 0) { + hours = 12; // Midnight case + } else if (hours > 12) { + hours -= 12; // Convert to 12-hour format + } + + return `${hours}:${minutes.toString().padStart(2, "0")} ${modifier}`; +} +function convertTo24HourClockTime(time12clock) { + let [time, modifier] = time12clock.split(" "); + let [hours, minutes] = time.split(":").map(Number); + + if (modifier === "PM" && hours !== 12) { + hours += 12; + } else if (modifier === "AM" && hours === 12) { + hours = 0; + } + + return `${hours.toString().padStart(2, "0")}:${minutes + .toString() + .padStart(2, "0")}`; +} +console.log(convertTo12HourClockTime(twentyFourHourClockTime)); // Output: "08:53 PM" +console.log(convertTo24HourClockTime(twelveHourClockTime)); // Output: "20:53" +// Output: "20:53" +// Output: "08:53 PM" From 7a0b1f7b765bd1ddb35d983f5e3128345d6cd6dd Mon Sep 17 00:00:00 2001 From: SuWebOnes Date: Tue, 24 Jun 2025 19:24:00 +0100 Subject: [PATCH 10/15] update: Fix minor formatting issues in comments and clarify variable reassignment in percentage change calculation --- .../1-percentage-change.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..b7a33b59e 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,23 @@ 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 5 function calls in this file. The code consists of variable assignments and calculations without any function definitions or calls. +// replaceAll(",", "") (twice) +// Number(...) (twice) +// console.log(...) (once) // 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? +// There are no errors in the code. The code runs successfully and calculates the percentage change in car price without any issues. // c) Identify all the lines that are variable reassignment statements +// The variable reassignment statements are: +// 1. carPrice = Number(carPrice.replaceAll(",", "")); +// 2. priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); // d) Identify all the lines that are variable declarations - +// The variable declarations are: +// 1. let carPrice = "10,000"; +// 2. let priceAfterOneYear = "8,543"; +// 3. const priceDifference = carPrice - priceAfterOneYear; +// 4. const percentageChange = (priceDifference / carPrice) * 100; // 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 string representation of the car price, which includes commas (e.g., "10,000"), into a number. The `replaceAll(",", "")` part removes all commas from the string, resulting in "10000", and then the `Number()` function converts this string into a numeric value (10000). This is necessary for performing arithmetic operations on the price. From 6992670bde333a81b3d99f82fa1bea0005fe7977 Mon Sep 17 00:00:00 2001 From: SuWebOnes Date: Tue, 24 Jun 2025 19:28:04 +0100 Subject: [PATCH 11/15] update: explain and comments for clarity in time format calculations sprint -1 of 2-time-format.js --- .../3-mandatory-interpret/2-time-format.js | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 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..87ef5c9f5 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -1,4 +1,4 @@ -const movieLength = 8784; // length of movie in seconds +const movieLength = 9000; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -12,14 +12,27 @@ 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. movieLength +// 2. remainingSeconds +// 3. totalMinutes +// 4. remainingMinutes +// 5. totalHours +// 6. result // b) How many function calls are there? +// their is 1 function call +// console.log(result); -// c) Using documentation, explain what the expression movieLength % 60 represents +// c) Using documentation, explain what the expression movieLength % 60 represents The is expressing remaining number of seconds after converted to 60 seconds +// The expression `movieLength % 60` calculates the remainder when `movieLength` (the length of the movie in seconds) +// This gives the number of seconds that do not complete a full minute, effectively representing the remaining seconds after converting the total movie length into minutes. // 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 (movieLength - remainingSeconds) / 60 determines the total number of full minutes in the movie by removing the leftover seconds and then dividing the result by 60. // e) What do you think the variable result represents? Can you think of a better name for this variable? - +//time +// The variable `result` represents the formatted time of the movie in the format "hours:minutes:seconds". +// A better name for this variable could be "movieDuration" to make it clearer that it holds the duration of the movie in a specific format. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer From ed5a315215974f4dd2d3d46aaa045ba775e7059f Mon Sep 17 00:00:00 2001 From: SuWebOnes Date: Tue, 24 Jun 2025 19:30:20 +0100 Subject: [PATCH 12/15] update: step-by-step breakdown of each line in this program and describe the purpose in sprint -1 of 3-to-pounds.js --- 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..f5a553523 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": initialize a string variable with the value "399p" +//2. Removes the trailing "p" from the string: and result will be 399 +//3. Ensures the number has at least 3 digits by padding from the left with zeros: like 000 +//4. Extracts the pound portion: "3" +//5.Extracts the pound portion: "99" +//6. Extracts the pound portion: in the standard monetary format of pounds and pence: "£3.99" From 7b076d81b1b3c5cd05e7e8b2fca9b4bd109b8580 Mon Sep 17 00:00:00 2001 From: SuWebOnes Date: Tue, 24 Jun 2025 19:33:21 +0100 Subject: [PATCH 13/15] update: explanations for alert and prompt functions in Chrome console sprint -1 of chrome.md --- 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..6a4bab498 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -11,8 +11,11 @@ In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? +This displays a popup box (called an "alert dialog") in the browser with the message: 'Hello world!' 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 popup input box appears asking: "What is your name?" What is the return value of `prompt`? +surafel From 2f5a89bd466ac1b3769fd9b3b7586938759fdd45 Mon Sep 17 00:00:00 2001 From: SuWebOnes Date: Tue, 24 Jun 2025 19:34:29 +0100 Subject: [PATCH 14/15] update: explanations for console methods and dot notation in sprint -1 of objects.md --- Sprint-1/4-stretch-explore/objects.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56..c4f6927a1 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -5,12 +5,15 @@ 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? - -Try also entering `typeof console` +console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} +Try also entering `typeof console` // object 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 `console` store? different functions (methods) like s log messages, show errors, warnings + +What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?`console.log` means accessing 'log' function inside 'console' object +`console.assert` mean accessing 'assert' function inside 'console' object +`.` is the dot notation and It’s used to access properties or methods of an object. From 2fc4c9090bbea1089e88625fefad24edbcdeb065 Mon Sep 17 00:00:00 2001 From: Surafel Date: Sat, 12 Jul 2025 11:49:21 +0100 Subject: [PATCH 15/15] Update 3-paths.js --- Sprint-1/1-key-exercises/3-paths.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index c31eca467..12c062494 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -12,19 +12,16 @@ 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}`); -// 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 = filePath; +const ext=base.slice(base.lastIndexOf(".") + 1); // The code uses the lastIndexOf method to find the position of the last dot in the base variable. +// Create a variable to store the dir part of the filePath variable +const dir = filePath.slice(0, lastSlashIndex);// The code uses the lastIndexOf method to find the position of the last slash in; filePath.slice(0, lastSlashIndex); -const ext = filePath; filePath .slice(lastSlashIndex + 1) .split(".") .pop(); -// The code above uses the lastIndexOf method to find the position of the last slash in the filePath string. -// The slice method is then used to extract the base part of the filePath string, which is the part after the last slash. - -// https://www.google.com/search?q=slice+mdn +console.log(`The dir part of ${filePath} is ${dir}`); +console.log(`The base part of ${filePath} is ${base}`); +console.log(`The ext part of ${filePath} is ${ext}`);