Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1b5ce16
Clarify the assignment operation in count.js
Monsur0001 Sep 19, 2026
6f2377a
Implement initials extraction from first, middle, and last names
Monsur0001 Sep 19, 2026
78f922e
Extracts first characters from firstname, middlename and lastname in …
Monsur0001 Sep 19, 2026
1ca86a4
Implement extraction of directory and extension from file path in 3-p…
Monsur0001 Sep 19, 2026
6fd351c
Fix typo in explanation of assignment operation in count.js
Monsur0001 Sep 19, 2026
b117813
Enhance documentation in 4-random.js to clarify the random number gen…
Monsur0001 Sep 19, 2026
fa638a8
Add comments to clarify instructions in 0.js for better readability
Monsur0001 Sep 19, 2026
4c61057
Change age variable from const to let for reassignment
Monsur0001 Sep 19, 2026
9de5303
Fix console log placement to ensure cityOfBirth is defined before usage
Monsur0001 Sep 19, 2026
2c371d5
Fix cardNumber definition to use string format and ensure last4Digits…
Monsur0001 Sep 19, 2026
c52b17e
Fix variable naming for clock time constants to follow camelCase conv…
Monsur0001 Sep 19, 2026
2ebfefd
Fix typo in replaceAll function call for priceAfterOneYear and update…
Monsur0001 Sep 19, 2026
e16a1ca
Experiment movieLength to a negative value and enhance comments for c…
Monsur0001 Sep 19, 2026
c9aaa7a
Step-by-step breakdown of the price conversion process
Monsur0001 Sep 26, 2026
ab1e16c
Specify that Math.random() includes 0 but not 1, using the inclusion …
Monsur0001 Sep 26, 2026
1421faf
Fix variable naming for clock time constants to follow camelCase conv…
Monsur0001 Sep 26, 2026
209b644
Clarify error explanation regarding missing comma in replaceAll funct…
Monsur0001 Sep 26, 2026
623bd7d
Clarify explanation to reflect the word "Argument" and Refactor comme…
Monsur0001 Sep 26, 2026
b381b0d
Refactor variable name suggestion for clarity in time formatting
Monsur0001 Sep 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Sprint-2/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ 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 updated the value of the variable "count". The "=" operator is an
assignment operator, which takes the value on the right side
("count + 1") and assigns it to the variable on the left side
("count"). So, it takes the current value of "count", adds 1 to it, and then
stores that new value back into "count"..
3 changes: 2 additions & 1 deletion Sprint-2/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const 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.

const initials = ``;
const initials = firstName[0] + middleName[0] + lastName[0];


// https://www.google.com/search?q=get+first+character+of+string+mdn
4 changes: 2 additions & 2 deletions Sprint-2/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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(".") + 1);

// https://www.google.com/search?q=slice+mdn
18 changes: 18 additions & 0 deletions Sprint-2/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,21 @@ 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 //represents a random integer between the minimum value (1) and the maximum value (100).Math

(maximum - minimum + 1) //represents the range of possible values, which is 100 - 1 + 1 = 100.
// This means that there are 100 possible values that num can take on.

Math.random() //generates a random decimal number between 0 and 1. This means that the value of Math.random()
// can be any number between 0 and 1, including 0 but not including 1.

Math.floor(Math.random() * (maximum - minimum + 1)) //multiplies the random decimal number generated by Math.random()
// by the range of possible values (100), and then rounds down to the nearest integer using Math.floor().
// This means that the result will be a random integer between 0 and 99.

Math.floor(Math.random() * (maximum - minimum + 1)) + minimum //adds the minimum value (1) to the result of the previous
// expression. This means that the final result will be a random integer between 1 and 100, inclusive.



4 changes: 2 additions & 2 deletions Sprint-2/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -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?
//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?
2 changes: 1 addition & 1 deletion Sprint-2/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
let age = 33;
age = age + 1;
3 changes: 2 additions & 1 deletion Sprint-2/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// 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}`);

15 changes: 14 additions & 1 deletion Sprint-2/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
const cardNumber = 4533787178994213;
const cardNumber = "4533787178994213";
const last4Digits = cardNumber.slice(-4);
Comment on lines -1 to 2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppose you were not allowed to modify the statement const cardNumber = 4533787178994213;
(that is, keep the variable's value unchanged).
How would you modify the code (through type conversion) to still being able to use .slice(-4) to extract the last 4 digits from the given number.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could also do same by converting card number to string using cardNumber.toString().slice(-4).

I had used the (“”) to convert the digits to String in this code

console.log(last4Digits);

// 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

The code is not working because the "slice" method is being used incorrectly. The "slice"
method should be called on the string "cardNumber" to extract the last 4 digits. However,
if there is a syntax error or if the variable "cardNumber" is not defined correctly, it could lead to an error.

// 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?
It gives an error because the "slice" method is being called on a string, but if the string is not defined correctly or
if there is a typo in the variable name, it will result in an error. This is what I predicted, as
I anticipated that the issue would be related to how the "slice" method is being used on the string.

// Then try updating the expression last4Digits is assigned to, in order to get the correct value

I updated the expression to correctly use the "slice" method on the "cardNumber" string. I converted the cardNumber to a
string with the ("") and then used the slice method to extract the last 4 digits.
4 changes: 2 additions & 2 deletions Sprint-2/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const 12HourClockTime = "8:53pm";
const 24hourClockTime = "20:53";
const twelveHourClockTime = "8:53pm";
const twentyFourHourClockTime = "20:53";
27 changes: 25 additions & 2 deletions Sprint-2/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,11 +12,34 @@ 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 five function calls in this file. The lines where function calls are made are:
//1. Line 4: carPrice.replaceAll(",", "")
//2. Line 5: priceAfterOneYear.replaceAll(",", "")
//3. Line 7: Number(carPrice.replaceAll(",", ""))
//4. Line 8: Number(priceAfterOneYear.replaceAll(",", ""))
//5. 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?

//The error is occurring on line 5 because a comma is missing between the arguments in the replaceAll function, to fix the problem,
//we need to include the "," character in the replaceAll function like this: priceAfterOneYear.replaceAll(",", "")

// c) Identify all the lines that are variable reassignment statements

// d) Identify all the lines that are variable declarations
//The lines that are variable reassignment statements are:
//1. Line 4: carPrice = Number(carPrice.replaceAll(",", ""));
//2. Line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));

// d) Identify all the lines that are variable declarations
//The lines that are variable declarations are:
//1. Line 1: let carPrice = "10,000";
//2. Line 2: let priceAfterOneYear = "8,543";
//3. Line 6: const priceDifference = carPrice - priceAfterOneYear;
//4. Line 7: 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 performing two main operations:
//1. "carPrice.replaceAll(",", "")": This part of the expression removes all commas from the string representation of
//"carPrice". For example, it converts "10,000" to "10000".
//2. "Number(priceAfterOneYear.replaceAll(",", ""));": This part converts the resulting string (after removing commas)
//into a numeric value. The purpose of this expression is to convert the string representation of a number that
//may contain commas into an actual numeric value that can be used for mathematical calculations.
28 changes: 27 additions & 1 deletion Sprint-2/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const movieLength = 8784; // length of movie in seconds
const movieLength = -9876; // length of movie in seconds

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -11,15 +11,41 @@ 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 six variable declarations in this program. The lines where variable declarations are made:
//1. Line 1: const movieLength = 8784;
//2. Line 3: const remainingSeconds = movieLength % 60;
//3. Line 4: const totalMinutes = (movieLength - remainingSeconds) / 60;
//4. Line 6: const remainingMinutes = totalMinutes % 60;
//5. Line 7: const totalHours = (totalMinutes - remainingMinutes) / 60;
//6. Line 9: const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;

// b) How many function calls are there?
//There are two function calls in this program. The lines where function calls are made are:
//1. Line 9: `${totalHours}:${remainingMinutes}:${remainingSeconds}`;
//2. 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 expression "movieLength % 60" calculates the remainder when the value of "movieLength" is divided by 60.
//In this context, it is used to determine the number of seconds remaining after converting the total movie
//length from seconds into minutes. Since there are 60 seconds in a minute, this operation effectively gives us the
//leftover seconds that do not make up a full minute.

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
//The expression assigned to "totalMinutes" in line 4 calculates the total number of minutes in the movie length.
//It does this by first subtracting the remaining seconds (calculated in line 3) from the total movie length in seconds.
//This gives the total number of seconds that can be fully converted into minutes. Then, it divides that value by 60 to
//convert the total seconds into total minutes. The result is the total number of complete minutes in the movie length,
//excluding any leftover seconds.

// 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 string in the format "hours:minutes:seconds".
// A better name for this variable could be "formattedTime"

// 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 positive integer values of movieLength, as it correctly calculates the hours, minutes,
//and seconds based on the total length in seconds. But will not work for negative values of movieLength,
//as it will produce negative hours, minutes, and seconds, which does not make sense in the context of a movie length.
7 changes: 6 additions & 1 deletion Sprint-2/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -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": initialises a string variable with the value "399p"
// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): removes the trailing "p" from the string, resulting in "399"
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): pads the string with leading zeros to ensure it has at least 3 characters, resulting in "399"
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): extracts the pounds part of the string by taking all characters except the last two, resulting in "3"
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): extracts the pence part of the string by taking the last two characters and pads it with trailing zeros if necessary, resulting in "99"
// 6. console.log(`£${pounds}.${pence}`): outputs the final formatted price in pounds and pence, resulting in "£3.99"
Loading