Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
285587f
answered 1-count,js
RaeesStevens Sep 26, 2026
647de99
added first character variable
RaeesStevens Sep 26, 2026
484ff89
edit prep files
RaeesStevens Sep 26, 2026
62ce6cc
updated template literal
RaeesStevens Sep 26, 2026
c1f4e1e
added template literal for intitials
RaeesStevens Sep 28, 2026
e736c2d
added console.log to initials.js
RaeesStevens Oct 1, 2026
1ce816b
removed inverted commas from console.log
RaeesStevens Oct 1, 2026
1d5ad56
added slice to dir variable
RaeesStevens Oct 1, 2026
775c3f5
corrected grammar in const dir
RaeesStevens Oct 1, 2026
868d352
Added LastDotIndex variable
RaeesStevens Oct 1, 2026
e6e1610
added ext print function
RaeesStevens Oct 1, 2026
ad31727
removed quotes in sliced ext variable
RaeesStevens Oct 1, 2026
edb729d
added print function to random,js
RaeesStevens Oct 1, 2026
d6ea3d3
unpacked expressions
RaeesStevens Oct 1, 2026
6e1a31f
added let
RaeesStevens Oct 1, 2026
dd2cdbc
Added print function
RaeesStevens Oct 1, 2026
d77e8e2
removed second declaration of age variable
RaeesStevens Oct 1, 2026
0bec30f
removed back ticks and replaced with quotes
RaeesStevens Oct 1, 2026
ecbb8e1
put variable above print function
RaeesStevens Oct 1, 2026
216b40b
put variable first
RaeesStevens Oct 1, 2026
8cb21df
added print function for last4Digits
RaeesStevens Oct 1, 2026
624fc64
added template literal
RaeesStevens Oct 1, 2026
a5119eb
added $ to template literal
RaeesStevens Oct 1, 2026
58e31bf
added explanation for answer
RaeesStevens Oct 1, 2026
5f2d6e0
Added print function for 12hour clocl
RaeesStevens Oct 1, 2026
43087db
changed numbers to words in variables
RaeesStevens Oct 1, 2026
a5213f2
added print for 24 hour clock time
RaeesStevens Oct 1, 2026
3145e30
answered a)
RaeesStevens Oct 2, 2026
72dfb0c
answered b)
RaeesStevens Oct 2, 2026
6edc642
corrected answeer a
RaeesStevens Oct 2, 2026
efd42ad
answered e) and added line numbers to c) and d)
RaeesStevens Oct 2, 2026
a2df7b1
updated c, d and e
RaeesStevens Oct 2, 2026
4e87ea5
added d and e answers
RaeesStevens Oct 2, 2026
ddaeb22
answered all questions
RaeesStevens Oct 3, 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
1 change: 1 addition & 0 deletions Prep
Submodule Prep added at 4035ae
2 changes: 2 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,5 @@ 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

// = in line 3 is assigning the rule that counting must start at 0.
7 changes: 6 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,11 @@ 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]}`;

console.log(initials);

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



9 changes: 6 additions & 3 deletions Sprint-2/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);
console.log(dir);
const lastDotIndex = base.lastIndexOf(".");
const ext = base.slice(lastDotIndex + 1);
console.log(ext);

// https://www.google.com/search?q=slice+mdn
// https://www.google.com/search?q=slice+mdn
5 changes: 5 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,8 @@ 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

console.log(num);

// num represents any randomly generated number between 1 and 100.
// Math.random pulls a random decimal, Math.floor rounds down to nearest whole number, (maximum - minimum + 1) sets the range, adding the minimum of 1 at the end allows for the possibility of a random number being 100 instead of 99.
5 changes: 4 additions & 1 deletion Sprint-2/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// 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);

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

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

// Card Number is declared as a number and not a string, so slice won't work.
console.log(last4Digits);
// Yes this is what I predicted. The error is - cardNumber.slice is not a function.
// I used a template literal because it will automatically convert the number to a string before slicing.
8 changes: 6 additions & 2 deletions Sprint-2/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
const 12HourClockTime = "8:53pm";
const 24hourClockTime = "20:53";
const twelveHourClockTime = "8:53pm";
const twentyFourhourClockTime = "20:53";

console.log(twelveHourClockTime);
console.log(twentyFourhourClockTime);

18 changes: 17 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,27 @@ 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.
// carPrice = Number(carPrice.replaceAll(",", ""));
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
// console.log(`The percentage change is ${percentageChange}`);


// 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 coming from line 5. There is a separator missing from the function call. Insert a comma to fix the problem.

// c) Identify all the lines that are variable reassignment statements
// Line 4 carPrice = Number(carPrice.replaceAll(",", ""));
// Line 5 priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));

// d) Identify all the lines that are variable declarations
// 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;

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// carPrice.replaceAll(",", "") removes every comma from the string, turning "10,000" into "10000".
// Number(...) then converts that string into the number 10000.
// The purpose is to turn a formatted price string into a real number so it can be used in calculations.
// Without the commas removed, Number("10,000") would return NaN.
11 changes: 11 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,25 @@ 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.

// b) How many function calls are there?
// There is 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. It returns what is left over after dividing one number by another.
// movieLength % 60 gives the seconds left over once all the full minutes are taken out of the movie length.
// 8784 % 60 = 24, because 8784 seconds is 146 full minutes with 24 seconds left over.

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// It subtracts the leftover seconds from the movie length, leaving a number that divides evenly by 60
// (8784 - 24 = 8760), then divides by 60 to get the number of whole minutes (8760 / 60 = 146).
// So totalMinutes is the total number of complete minutes in the movie.

// 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 would be movieLengthHHMMSS.

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

25 changes: 25 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,28 @@ console.log(`£${pounds}.${pence}`);

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

// 3. const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1):
// Takes the characters from index 0 up to (but not including) the last character.
// penceString.length is 4, so this is substring(0,3), resulting in "399".
// The purpose is to remove the "p" so only digits remain.

// 8. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0")
// Adds "0"s to the start until the string is at least 3 characters long.
// The purpose is to guarantee at least one digit for pounds and two digits for pence.

// 9. const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2);
// The purpose is to make the pounds all the digits before the last two, by taking everything except the last two characters: substring(0,1), giving "3"

// 14. const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
// substring(1) takes from index 1 to the end, giving "99".
// padEnd(2, "0") adds "0"s to the end until it is two characters long, so "99" stays "99".
// The purpose is too ensure the pence are always the last two digits.
// The padEnd does not change anything here since line 8 already guarantees at leas 3 characters, so the last two characters always exist.

// 18. console.log(`£${pounds}.${pence}`);
// Call function using a template literal to combine "£", the pounds, a ".", and the pence, then prints "£3.99".




Loading