Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
adf7716
Complete count and initials exercises
lauracs24 Feb 9, 2026
076d4b1
Fix mismatched quotes in paths exercise
lauracs24 Feb 9, 2026
19051a8
Replace placeholder with dir and ext extraction
lauracs24 Feb 9, 2026
89aa4c4
Log and explore Math.random output
lauracs24 Feb 9, 2026
a24af55
Log range used for random number generation
lauracs24 Feb 9, 2026
01c50bb
I scaled random decimal to configured range
lauracs24 Feb 9, 2026
c74b4b5
Round scaled random number down to whole number
lauracs24 Feb 9, 2026
38fc7f0
Explain final random number generation
lauracs24 Feb 9, 2026
6329c3b
Commented out instructions to prevent JavaScript syntax errors
lauracs24 Feb 9, 2026
abb1513
Fix reassignment error by using let instead of const
lauracs24 Feb 9, 2026
39253b5
I fixed template string and variable order error
lauracs24 Feb 9, 2026
03d2804
Fix slice error by converting number to string
lauracs24 Feb 9, 2026
ab26532
Fix invalid variable names starting with numbers
lauracs24 Feb 9, 2026
28644c4
Fix replaceAll syntax and calculate percentage change
lauracs24 Feb 9, 2026
4f3358b
Answer interpretation questions for time format
lauracs24 Feb 9, 2026
3f4ddcc
Explain step-by-step conversion from pence to pounds
lauracs24 Feb 10, 2026
b40ee1f
Added a stylistic change
lauracs24 Feb 10, 2026
3ee79aa
Remove redundant padEnd and update explanation
lauracs24 Feb 18, 2026
15e22b2
Fix explanation for syntax error in part b
lauracs24 Feb 18, 2026
2bf18ae
Added increment explanation
lauracs24 Feb 18, 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
4 changes: 3 additions & 1 deletion Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ 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
// I see that line 3 performs an increment operation.
// It increases the value of count by 1 and assigns the new value back to the variable.
// The = is the assignment operator — it assigns the result of (count + 1) back to count.
4 changes: 2 additions & 2 deletions Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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

9 changes: 6 additions & 3 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(".") + 1);

// https://www.google.com/search?q=slice+mdn
console.log(dir);
console.log(ext);

// https://www.google.com/search?q=slice+mdn
20 changes: 20 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,23 @@ 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

// Math.random() generates a random decimal number between 0 - inclusive and 1 (exclusive)
const randomDecimal = Math.random();
console.log("randomDecimal:", randomDecimal);
// Calculate how many numbers are in the range between minimum and maximum (inclusive)
const range = maximum - minimum + 1;
console.log("range:", range);
// Scale the random decimal to fit within the range...
const scaledNumber = randomDecimal * range;
console.log("scaledNumber:", scaledNumber);
// Round the scaled number down to the nearest whole number
const wholeNumber = Math.floor(scaledNumber);
console.log("wholeNumber:", wholeNumber);
// Shift the number so it starts from the minimum value...
const finalNumber = wholeNumber + minimum;
console.log("finalNumber:", finalNumber);

// The variable num is a random whole number between minimum and maximum - inclusive
console.log("num:", num);

4 changes: 2 additions & 2 deletions Sprint-1/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?
4 changes: 3 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// 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);

5 changes: 3 additions & 2 deletions Sprint-1/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 ?
// The error is caused by using the variable before it is declared
// and by using single quotes instead of backticks for a template string

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);
11 changes: 10 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
const last4Digits = cardNumber.toString().slice(-4);
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
// 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:
// cardNumber is a number, not a string
// The slice method only works on strings (and arrays)
// So calling slice on a number will cause an error

7 changes: 5 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
// The error occurs because variable names cannot start with numbers
// JavaScript identifiers must begin with a letter, $ or _

const twelveHourClockTime = "20:53";
const twentyFourHourClockTime = "08:53";
34 changes: 29 additions & 5 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,45 @@ 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;

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
// Function calls are when we use () like: something()
// Line 4: carPrice.replaceAll(",", "")
// Line 4: Number(...)
// Line 5: priceAfterOneYear.replaceAll(",", "")
// Line 5: Number(...)
// Line 10: console.log(...)
// My answer: 5 function calls

// 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 comes from line 5:
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
// I think there is a syntax error because a comma is missing between the two arguments of replaceAll.
// JavaScript expects: replaceAll(",", "")
// To fix the problem, add the missing comma:
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));

// c) Identify all the lines that are variable reassignment statements
// Reassignment means I change an existing variable's value (no let/const on the line)
// Line 4: carPrice = Number(carPrice.replaceAll(",", ""));
// Line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
// My answer- I think lines 4 and 5

// 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?
// Declarations use let or const
// Line 1: let carPrice = "10,000";
// Line 2: let priceAfterOneYear = "8,543";
// Line 7: const priceDifference = carPrice - priceAfterOneYear;
// Line 8: const percentageChange = (priceDifference / carPrice) * 100;
// Answer- lines 1, 2, 7 and 8

// e) Describe what the expression Number(carPrice.replaceAll(",", "")) is doing - what is the purpose of this expression?
// replaceAll(",", "") removes commas from the string (e.g. "10,000" becomes "10000")
// Number(...) converts the cleaned string into a real number so we can do maths with it
// Purpose: turn "10,000" (text) into 10000 (number)
29 changes: 26 additions & 3 deletions Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,40 @@ const totalHours = (totalMinutes - remainingMinutes) / 60;
const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;
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?
// Declarations are lines that use const or let
// const movieLength
// const remainingSeconds
// const totalMinutes
// const remainingMinutes
// const totalHours
// const result
// My answer: 6 variable declarations

// b) How many function calls are there?
// A function call uses parentheses like something(..)
// console.log(result) is a function call
// My answer: 1 function call

// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
// % is the remainder operator
// movieLength % 60 gives the leftover seconds after dividing by 60
// (the seconds part that doesn't make a full minute)
// Answer: it represents the remaining seconds

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// totalMinutes = (movieLength - remainingSeconds) / 60
// First it removes the leftover seconds so we have an exact number of seconds that fits into whole minutes
// Then it divides by 60 to convert seconds into minutes
// Answer: it calculates the total whole minutes in the movie

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// result is a string that formats the time as hours:minutes:seconds
// Better name: formattedTime or movieDuration

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// It works for normal positive numbers (seconds) like 8784
// It will also run for 0 (gives 0:0:0)
// But negative values would produce negative hours/minutes/seconds, which isn't a real time format
// So it assumes movieLength is a non-negative number

53 changes: 46 additions & 7 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,61 @@ const penceStringWithoutTrailingP = penceString.substring(
);

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");

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
);

console.log(`£${pounds}.${pence}`);

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

// You need to do a step-by-step breakdown of each line in this program
// Try and describe the purpose / rationale behind each step
// 1. const penceString = 399p
// Creates a string representing a price in pence, including the letter "p".
// Example: 399p
// This is the original input value we want to convert into pounds.


// 2. const penceStringWithoutTrailingP = ...
// It uses substring to remove the last character ("p") from the string.
// We take the string from index 0 up to but not including the last character.
// Result: 399
// This leaves only the numeric part of the price as a string.


// 3. const paddedPenceNumberString = ...
// padStart makes sure the string is at least 3 characters long.
// This is important for small values like 5p:
// 5 becomes 005
// Result for "399": "399"
// Result for "5p": "005"


// 4. const pounds = ...
// Basically extracts all characters except the last two.
// The last two characters represent pence,
// everything before that represents pounds.
// For "399":
// pounds = "3"


// 5. const pence = ...
// Takes the last two characters of the string.
// Because padStart ensured the string is at least 3 characters long,
// substring will always return exactly two characters.
// For "399":
// pence = "99"


// 6. console.log(`£${pounds}.${pence}`)
// Combines pounds and pence into a formatted price string.
// Final output for "399p":
// £3.99


// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"