Skip to content
10 changes: 9 additions & 1 deletion Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
let count = 0;

count = count + 1;
count = count + 3;

// 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 updating the value of the count variable by adding 1 to its current value. The = operator
// is used to assign the new value (count + 1) back to the count variable.
// we can also say that the = operator is taking the value on the right side (count + 1) and storing it
// in the variable on the left side (count).

// We can see the result of our code by logging the count variable to the console
console.log(count);
9 changes: 8 additions & 1 deletion Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ 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 = ``;
// You can use the .charAt() method of strings to get a character at a specific position in a string.
// The first character is at position 0, the second at position 1, and so on.


let initials = firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0);

// https://www.google.com/search?q=get+first+character+of+string+mdn

// Log the initials variable to the console
console.log(initials);

17 changes: 15 additions & 2 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@ 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 = ;
// The dir part is everything before the base part
// The ext part is everything after the last "." in the base part

// You can use the .lastIndexOf() method of strings to find the position of the last occurrence of a specific character in a string.
// For the dir part, you need to find the position of the last "/" in the filePath string.
// For the ext part, you need to find the position of the last "." in the base string.

const dir = filePath.slice(0, lastSlashIndex + 1); // this will include the last "/"
// if you don't want the last "/", use lastSlashIndex instead of lastSlashIndex + 1

const ext = base.slice(base.lastIndexOf(".")); // this will include the "."
// if you don't want the ".", use filePath.lastIndexOf(".") + 1 instead of filePath.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
16 changes: 16 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ const maximum = 100;
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;

// In this exercise, you will need to work out what num represents?
// num is a variable that stores a random integer between minimum and maximum.
// the num variable is calculated using the Math.random() function, which generates a random floating-point number between 1 and 100.

// Try breaking down the expression and using documentation to explain what it means
// const num stores the result of the expression on the right-hand side of the equals sign
// the = expression is used to assign a value to a variable
// the expression (maximum - minimum + 1) calculates the range of numbers between minimum and maximum.
// adding minimum shifts the range to start from the minimum value instead of 0.

// It will help to think about the order in which expressions are evaluated
// 1. (maximum - minimum + 1) is evaluated first, resulting in 100
// 2. Math.random() is called, generating a random floating-point number between 0 (inclusive) and 1 (exclusive)
// 3. The result of Math.random() is multiplied by the result of (maximum - minimum + 1), scaling the random number to the desired range
//

// Try logging the value of num and running the program several times to build an idea of what the program is doing
// The running the the program several times you can see that the program is generating a random number between 1 and 100.

console.log(num);
9 changes: 7 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
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? */

// we can use // to comment out a single line
// or we can use /* to start a multi-line comment
// and end it with */

7 changes: 6 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
let age = 33;
age = age + 1;

// to reassign the value of age by 1 we need to use let instead of const

console.log(age);

4 changes: 3 additions & 1 deletion Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Currently trying to print the string "I was born in Bolton" but it isn't working...
// what's the error ?
// we need to declare the variable before we use it in the console.log statement


console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);
14 changes: 13 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
//const last4Digits = cardNumber.slice(-4);

// The last4Digits variable should store the last 4 digits of cardNumber

// However, the code isn't working
// the error is that slice is not a function for numbers, it is a function for strings and arrays

// Before running the code, make and explain a prediction about why the code won't work
// My prediction is that the code will give an error because slice is not a function for numbers

// Then run the code and see what error it gives.
// typeError: cardNumber.slice is not a function

// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
// It gives this error because slice is not a function for numbers, it is a function for strings and arrays. This is what I predicted.

// Then try updating the expression last4Digits is assigned to, in order to get the correct value
const cardNumberString = cardNumber.toString();
const last4DigitsCorrected = cardNumberString.slice(-4);
console.log(last4DigitsCorrected); // Should print 4213
14 changes: 12 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const a24HourClockTime = "20:53";
const a12hourClockTime = "08:53";

// The 12HourClockTime variable should store the time in 12-hour format
// The 24hourClockTime variable should store the time in 24-hour format

// However, the code isn't working
// the error is that the variable names are not valid because they start with a number
// Variable names cannot start with a number

console.log(a24HourClockTime); // Should print: 08:53
console.log(a12hourClockTime); // Should print: 20:53
8 changes: 7 additions & 1 deletion Sprint-1/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,17 @@ 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, they are on lines 1, 2, 5, 6 and 9

Choose a reason for hiding this comment

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

Are you sure these numbers are correct? How are you identifying function calls?

Copy link
Author

Choose a reason for hiding this comment

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

Hello,

Thank you for the feedback.

there are 5 function calls and, they are on lines 4, 5, and 10
function calls: replaceAll(), replaceAll(), Number(), Number(), 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 was coming from line 5 there was a comma missing between the 2 quotations ("," "") by adding the comma the code was fixed and it worked as it should.

// c) Identify all the lines that are variable reassignment statements
// the variable reassignment statements are on lines 5 and 6

Choose a reason for hiding this comment

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

Are you sure these are the correct lines? How are you counting the lines?

Copy link
Author

Choose a reason for hiding this comment

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

The variable reassignments are on lines 4 and 5

The variable reassignments are: carPrice = Number(carPrice.replaceAll(",", "")), priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")).


// d) Identify all the lines that are variable declarations
// the variable declaration statements are on lines 1, 2, 4, 7 and 8

Choose a reason for hiding this comment

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

What is the variable declaration on line 4?

Copy link
Author

Choose a reason for hiding this comment

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

There is no variable declaration on line 4. there are only 4 variable declarations

the variable declaration statements are on lines 1, 2, 7 and 8
The variable declarations are: let carPrice, let priceAfterOneYear, const priceDifference, const percentageChange


// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
/* the expression is taking the variable carPrice and replacing all the commas in the string with nothing and then converting
the string into a number so that it can be used in calculations.*/
10 changes: 9 additions & 1 deletion Sprint-1/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 = 7784; // length of movie in seconds

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -12,14 +12,22 @@ 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 in this program. They are on lines 1, 3, 4, 6, 7 and 9

// b) How many function calls are there?
// there are 2 function calls in this program. They are on lines 9 and 10

Choose a reason for hiding this comment

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

Which functions are called on lines 9 and 10?

Copy link
Author

Choose a reason for hiding this comment

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

Hello,

Thank you for the feedback there is only one function call in the script in question and the function call is in line 10 and the function call is 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 is using the modulus operator (%) to find the remainder when movieLength (8784) is divided by 60.

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
/* line 4 is calculating the total number of minutes in the movie by subtracting the remaining seconds from the total movie length in
seconds and then dividing that result 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 total length of the movie in hours, minutes and seconds. A better name for this variable could

Choose a reason for hiding this comment

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

Is it clear what the difference is between movieDuration and movieLength? Could I understand the difference by quickly reading these two variable names?

Copy link
Author

@AdnaanA AdnaanA Oct 6, 2025

Choose a reason for hiding this comment

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

Not really — they could easily be confused, especially in a larger codebase where someone is scanning quickly.

we can change movieDuration to something like formattedmovieDuration

be movieDuration.*/

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// yes this code will work for all values of movieLength as long as the value is a non-negative integer representing the length of a movie in seconds.

Choose a reason for hiding this comment

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

Are you sure there are no values that might give unexpected or oddly formatted output?

Copy link
Author

Choose a reason for hiding this comment

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

The code will work correctly, but it can produce unexpected or oddly formatted output in terms of readability, especially for values less than 10.

Expected value: 02:09:44
current code value: 2:9:44

12 changes: 6 additions & 6 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
const penceString = "399p";
const penceString = "1399p"; // stores the price in pence as a string with a trailing 'p'

const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);
); // removes the trailing 'p' from the string to isolate the numeric part

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);
); // extracts the pounds part by taking all but the last two characters

const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");
.substring(paddedPenceNumberString.length - 2) // extracts the last two characters as the pence part
.padEnd(2, "0"); // ensures the pence part is two digits by padding with '0' if necessary

console.log(`£${pounds}.${pence}`);
console.log(`£${pounds}.${pence}`); // outputs the formatted price in pounds and pence

// This program takes a string representing a price in pence
// The program then builds up a string representing the price in pounds
Expand Down
Loading