From 326e5d6e5cf79675f7b27258ca0ebb5b5f13d314 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 29 Sep 2025 18:37:37 +0100 Subject: [PATCH 01/14] 1-count.js --- Sprint-1/1-key-exercises/1-count.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..e7affbbeb 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -3,4 +3,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 3 is an assignment statement. The = is the assignment operator, which takes the value on the right side (count + 1, which evaluates to 1) and assigns it to the variable on the left side (count), updating count's value from 0 to 1 From 845eefaa84ab3c07a43fb2fa6d7cb2137e34deb8 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 29 Sep 2025 18:45:17 +0100 Subject: [PATCH 02/14] 2-initials.js --- 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..5a7c183c5 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.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`; +console.log(initials); // https://www.google.com/search?q=get+first+character+of+string+mdn From 9ae7180d54dc457b4e72b303666bf3ea3fd5a0dc Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 29 Sep 2025 18:53:15 +0100 Subject: [PATCH 03/14] 3-paths.js --- Sprint-1/1-key-exercises/3-paths.js | 7 +++++-- 1 file changed, 5 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..e128f1ea3 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 = base.slice(base.lastIndexOf(".")); + +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 49913e8e6c336f57e5e2df43e86a53669f8a9e25 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 29 Sep 2025 19:03:12 +0100 Subject: [PATCH 04/14] 4-random.js --- Sprint-1/1-key-exercises/4-random.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..3e64d6cf6 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -1,9 +1,23 @@ const minimum = 1; const maximum = 100; -const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; +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 + +// Breaking down what num represents: +// num generates a random integer between 1 and 100 (inclusive) + +// Step-by-step evaluation: +// 1. Math.random() → generates a decimal between 0 (inclusive) and 1 (exclusive) +// 2. (maximum - minimum + 1) → calculates the range size: (100 - 1 + 1) = 100 +// 3. Math.random() * 100 → gives a decimal between 0 and 99.999... +// 4. Math.floor(...) → rounds down to get integers from 0 to 99 +// 5. + minimum → shifts the range from 0-99 to 1-100 + +// So num represents a random integer from 1 to 100 From 6efbcb4ecc0c028074c5e190566c91710de585f9 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 29 Sep 2025 19:13:15 +0100 Subject: [PATCH 05/14] 0.js --- Sprint-1/2-mandatory-errors/0.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..bbf9b56b7 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,3 @@ 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? +By adding // at the beginning of each line to turn the text into comments. \ No newline at end of file From c76b3f487749848e922db6467cfc20b7b7c1d0f5 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 29 Sep 2025 19:17:15 +0100 Subject: [PATCH 06/14] 1.js --- Sprint-1/2-mandatory-errors/1.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..e57b2e979 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,5 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; +console.log(age); From 0600c9f677867db1ced019ebc26ae6aeb8406f5b Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 29 Sep 2025 19:20:37 +0100 Subject: [PATCH 07/14] 2.js --- Sprint-1/2-mandatory-errors/2.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..518a94a60 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,6 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? +//The variable cityOfBirth is being used before it's declared. To fix the error, we need to declare the variable before using it in the console.log statement. -console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); From 2c4af18caa479bb97b5c5d506572135d035c6181 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 29 Sep 2025 19:27:49 +0100 Subject: [PATCH 08/14] 3.js --- Sprint-1/2-mandatory-errors/3.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..d9036ab57 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,9 +1,11 @@ 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 -// 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: The code won't work because cardNumber is a number, but .slice() only works on strings and arrays +// ERROR: TypeError: cardNumber.slice is not a function +// SOLUTION: Convert the number to a string first using .toString() method +console.log(last4Digits); // Should output: "4213" +//The issue is that cardNumber is a number, but the .slice() method only works on strings (and arrays). +// Convert the number to a string first, then use .slice() \ No newline at end of file From c75419d1d2f7f2dfea1013144379005b481dfb16 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 29 Sep 2025 19:32:02 +0100 Subject: [PATCH 09/14] 4.js --- Sprint-1/2-mandatory-errors/4.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..9503852c4 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,5 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +//const 12HourClockTime = "20:53"; +//const 24hourClockTime = "08:53"; +// Variable names cannot start with a number +const twelveHourClockTime = "20:53"; +const twentyFourHourClockTime = "08:53"; \ No newline at end of file From ef37add7ac5430307696e4f9a4977cf34b55f7f3 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 29 Sep 2025 19:51:40 +0100 Subject: [PATCH 10/14] 1-percentage-change.js --- .../1-percentage-change.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..9e0b1949a 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -12,11 +12,29 @@ 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 +// 5 function calls +//Line 4: carPrice.replaceAll(",", "") +//Line 4: Number(...) – wraps the above +//Line 5: priceAfterOneYear.replaceAll(",", "") ✅ But this line has a syntax error (we’ll get to it) +//Line 5: Number(...) – wraps the above +//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? +//syntax error! On line 5, there's a missing comma in the replaceAll method. +//correct code should be +//priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); // c) Identify all the lines that are variable reassignment statements +carPrice = Number(carPrice.replaceAll(",", "")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); // d) Identify all the lines that are variable declarations +let carPrice = "10,000"; +let priceAfterOneYear = "8,543"; // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +// This expression converts a string with commas into a number that can be used for mathematical calculations: +// 1. carPrice.replaceAll(",", "") - removes all commas from the string "10,000" → "10000" +// 2. Number(...) - converts the cleaned string "10000" into the number 10000 +// Purpose: Strings with commas cannot be used in math operations, so we need to clean and convert them to numbers first From 596785a38b5d79b4bdbdc64a193668c5af1d0d04 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 29 Sep 2025 19:58:54 +0100 Subject: [PATCH 11/14] 2-time-format.js --- .../3-mandatory-interpret/2-time-format.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..4f084a25d 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -12,14 +12,33 @@ 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? +// 6 variable declarations +//Line 1: movieLength +//Line 3: remainingSeconds +//Line 4: totalMinutes +//Line 6: remainingMinutes +//Line 7: totalHours +//Line 9: result // b) How many function calls are there? +// 1 function call +//Line 10: 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 +// The % operator is the remainder operator. It returns the remainder left over when one operand is divided by a second operand. +// In this case, movieLength % 60 calculates the number of seconds remaining after dividing the total movie length by 60 (the number of seconds in a minute). +// For example, if movieLength is 8784 seconds, then 8784 % 60 equals 24, meaning there are 24 seconds left over after accounting for full minutes. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// The expression (movieLength - remainingSeconds) / 60 calculates the total number of minutes in the movie by first removing the remaining seconds and then dividing by 60 (the number of seconds in a minute). // 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 string output of the total hours, remaining minutes, and remaining seconds of the movie. +// A better name for this variable could be formattedMovieLength. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// The code will work for all non-negative integer values of movieLength. It correctly calculates hours, minutes, and seconds for any length of time. +// However, if movieLength is negative or not an integer, the results may not make sense in the context of a movie length. +// For example, if movieLength is negative, the calculations for hours, minutes, and seconds will yield negative values, which are not valid for a movie duration. +// Additionally, if movieLength is a non-integer (e.g., a float), the calculations will still work, but the interpretation of the result may be less clear since movie lengths are typically represented as whole seconds. \ No newline at end of file From 5250a3ba5fde084014cc6c6ca0d3628bbd284fd8 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 29 Sep 2025 20:10:36 +0100 Subject: [PATCH 12/14] 3-to-pounds.js --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..c42e55592 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. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): removes the trailing 'p' from the string to isolate the numeric part +// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): pads the numeric string with leading zeros to ensure it is at least 3 digits long +// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): extracts the pounds portion from the padded string +// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): extracts the pence portion and ensures it is 2 digits long +// 6. console.log(`£${pounds}.${pence}`): outputs the final formatted string representing the price in pounds From 60669a00f15b06118ec31e2bebb1b95febf1c268 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 29 Sep 2025 20:21:47 +0100 Subject: [PATCH 13/14] 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..27a558094 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? +->It creat a pop up with the word "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? What is the return value of `prompt`? +-> It displays a dialog box in the browser asking the user to enter some input. +The user can type a response and click "OK" or click "Cancel". From 585c2359298cbb532e38a322de9a127ed136fbb4 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 29 Sep 2025 20:29:39 +0100 Subject: [PATCH 14/14] objects.md --- Sprint-1/4-stretch-explore/objects.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56..7e322bbc8 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -5,12 +5,19 @@ 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` +->'object' Answer the following questions: What does `console` store? +->console stores an object that contains functions for outputting information to the browser’s debugging console. + What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +->The . operator accesses a specific property or method on an object. console.log means "use the log function from the console object. +console.assert means access the assert function inside the console object. \ No newline at end of file