Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
f2e91c5
complete prep folder exercises
rahanasuleiman8-ship-it Sep 18, 2026
94e0982
Added description for what line 3 is doing, focusing more on what = does
rahanasuleiman8-ship-it Sep 18, 2026
0cad20d
declared a variable to store first characters of each string without …
rahanasuleiman8-ship-it Sep 18, 2026
14ba89d
create a variable to store both dir(filePath) and ext part of the var…
rahanasuleiman8-ship-it Sep 18, 2026
aeabc99
Add step-by-step explanation of Math.random, Math.floor, maximum, min…
rahanasuleiman8-ship-it Sep 18, 2026
814abb5
comment out what I don't want the computer to run
rahanasuleiman8-ship-it Sep 18, 2026
dc97183
change age variable declaration from 'const' to 'let' to allow reassi…
rahanasuleiman8-ship-it Sep 18, 2026
8ada20c
declare 'cityOfBirth' before 'console.log' to in 2.js to fix Referenc…
rahanasuleiman8-ship-it Sep 18, 2026
936de83
predict and explain the error in the code, and update the expression …
rahanasuleiman8-ship-it Sep 18, 2026
55fa5e7
predict and explain the error in the code, and update the expression …
rahanasuleiman8-ship-it Sep 18, 2026
2fc4870
Rename variables to match JavaScript naming conventions and verify co…
rahanasuleiman8-ship-it Sep 18, 2026
4922e00
-add missing comma between arguments in replaceAll() on line 5
rahanasuleiman8-ship-it Sep 18, 2026
bb34ab4
- verify variable declaration and function call count
rahanasuleiman8-ship-it Sep 18, 2026
23673ee
Fix: update in 3-paths.js
rahanasuleiman8-ship-it Sep 19, 2026
5f58ebd
Update commit
rahanasuleiman8-ship-it Sep 19, 2026
e8de7c3
- Add detailed explanation for substring, padStart, and padEnd methods
rahanasuleiman8-ship-it Sep 21, 2026
4f6289b
remove untracked githooks file from PR
rahanasuleiman8-ship-it Sep 21, 2026
88beb1f
remove prep directory files from Sprint 2 PR
rahanasuleiman8-ship-it Sep 21, 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
10 changes: 10 additions & 0 deletions Sprint-2/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,15 @@ let count = 0;

count = count + 1;


//const count = 0;
// count = count + 1;
// console.log(count)

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

//ANSWER:

// Line 3 is reassigning the value of count. This is because we are using "let" and not "const" which allows us to reassign values. The value of count is being evaluated first (count + 1), which sums up to (0 + 1 = 1) and then it is updated using the assignment operator (=), which takes the result and stores it back into the count variable.

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.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`;
console.log(initials);

// https://www.google.com/search?q=get+first+character+of+string+mdn
10 changes: 7 additions & 3 deletions Sprint-2/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ 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
const dir = filePath.slice(0, lastSlashIndex);

// Create a variable to store the ext part of the variable
const lastDotIndex = filePath.lastIndexOf(".");
const ext = filePath.slice(lastDotIndex);

const dir = ;
const ext = ;
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
// https://www.google.com/search?q=slice+mdn
14 changes: 11 additions & 3 deletions Sprint-2/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
const minimum = 1;
const maximum = 100;
const minimum = 1; // Sets the lowest possible number that can be generated
const maximum = 100; // Sets the highest possible number that can be generated

const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;

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

const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
// Math.random() returns a random decimal between 0 and 1
// Math.random() * maximum(100) returns a random decimal between 0 and 99.999
// Math.floor() rounds up the decimal to the nearest whole number
// maximum and minimum calculates thee total output of the number(100)

// 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); // num represents a random whole number between 1 and 100
9 changes: 7 additions & 2 deletions Sprint-2/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?*/


//ANSWER:

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

const age = 33;
// The problem here is that 'const' creates a constant variable which cannot be reassigned, attempting to reassign (age = age + 1) throws a TypeError: Assignment to constant variable.


//change 'const' to 'let' so the value can be updated
// const age = 33;
let age = 33;
age = age + 1;

// console.log(age);
9 changes: 8 additions & 1 deletion Sprint-2/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// 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}`);
// The error is a ReferenceError: Cannot access 'cityOfBirth' before initialization
// In JavaScript variables declared with 'const' or 'let' cannot be accessed before they are declared or initialized


//SOLUTION
// move the variable declaration above the 'console.log()'
const cityOfBirth = "Bolton";

console.log(`I was born in ${cityOfBirth}`);
17 changes: 14 additions & 3 deletions Sprint-2/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.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

//Prediction: The code won't work because cardNumber is stored as a Number and not a string, this is because '.slice()' is a string method
// Numbers in JavaScript don't work with '.slice()'


// Then run the code and see what error it gives.
//This is the 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?

//Explanation: Yes, my prediction was accurate. JavaScript threw a TypeError because '.slice()' is a string method
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
const cardNumber = '4533787178994213';
const last4Digits = cardNumber.slice(-4);

// console.log(last4Digits);
9 changes: 7 additions & 2 deletions Sprint-2/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
const 12HourClockTime = "8:53pm";
const 24hourClockTime = "20:53";
// JavaScript variable names cannot start with a number. They must start with an alphabet(A-Z), an underscore(_), or a dollar sign($). JavaScript is also case sensitive so they have to use camelCase, PascalCase, among others.

const HourClockTime = "8:53pm";
const hourClockTime = "20:53";

// console.log(HourClockTime);
// console.log(hourClockTime);
13 changes: 12 additions & 1 deletion 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,22 @@ 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
// ANSWER: There are 5 function calls along 3 lines
// Line 4: replaceAll() and Number()
// Line 5: replaceAll() and Number()
// 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?
// ANSWER: The error comes from Line 5 because a comma is missing between the two string arguments in replaceAll("," "").
// FIX: Add the missing comma to replaceAll(",", "")

// c) Identify all the lines that are variable reassignment statements
// ANSWER: Lines 4 and 5 (carPrice and priceAfterOneYear)

// d) Identify all the lines that are variable declarations
// ANSWER: Lines 1, 2, 7, and 8 (using let and const)

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// ANSWER: The expression Number(carPrice.replaceAll(",","")) removes the comma from the carPrice = "10,000" and converts it to "10000".
// Then, JavaScript can now convert the string into a number so it can be calculated.

14 changes: 14 additions & 0 deletions Sprint-2/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,28 @@ 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?
// ANSWER: There are 6 variable declarations.
// (movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, and result — all declared using const)

// b) How many function calls are there?
// ANSWER: There is only function call
// 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

//ANSWER: The expression movieLength % 60 uses the remainder (%) operator to calculate the number of seconds remaining that can't form a full seconds (8784 % 60 = 24 seconds)

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// ANSWER: The expression assigned to totalMinutes means division

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// ANSWER: It subtracts the remainder seconds from movieLength to get an exact multiple of 60, then divides by 60 to convert the seconds into whole minutes (146 minutes).

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// ANSWER: A better name for the variable would be 'formattedDuration' because it clearly describes that the variable stores the movie duration in a formatted hours, minutes, and seconds format.

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer

// ANSWER: No. It breaks if movieLength is negative (giving negative time) or a string.
// Additionally, single-digit minutes or seconds (e.g., 4 minutes, 8 seconds) output as "2:4:8" instead of standard "02:04:08" formatting.
5 changes: 5 additions & 0 deletions Sprint-2/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: uses substring to remove the trailing "p" from "399p", leaving "399"
// 3. const paddedPenceNumberString: padStart() makes sure the string has at least 3 characters, adding "0" if required. If we have "5p" and we remove the "p" we would be left with "5", so padding it to 3 numbers will give us the output ("005")
// const pounds: removes everything except the final two digits, giving "3".
// 4. const pence = paddedPenceNumberString: extracts the final two digits, giving "99", and ensures they have at least two characters and adds zero if necessary.
// 5. console.log(`£${pounds}.${pence}`): combines the pound and pence values into the formatted price with the template literals to give "£3.99"