Skip to content

Commit b8c0df3

Browse files
committed
Complete Sprint 1 mandatory exercises
1 parent 095f64d commit b8c0df3

8 files changed

Lines changed: 37 additions & 8 deletions

File tree

Sprint-1/2-mandatory-errors/0.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
This is just an instruction for the first activity - but it is just for human consumption
2-
We don't want the computer to run these 2 lines - how can we solve this problem?
1+
// This is just an instruction for the first activity - but it is just for human consumption
2+
// We don't want the computer to run these 2 lines - how can we solve this problem?

Sprint-1/2-mandatory-errors/1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// trying to create an age variable and then reassign the value by 1
22

3-
const age = 33;
3+
let age = 33;
44
age = age + 1;

Sprint-1/2-mandatory-errors/2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
22
// what's the error ?
33

4-
console.log(`I was born in ${cityOfBirth}`);
54
const cityOfBirth = "Bolton";
5+
console.log(`I was born in ${cityOfBirth}`);

Sprint-1/2-mandatory-errors/3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const cardNumber = 4533787178994213;
1+
const cardNumber = "4533787178994213";
22
const last4Digits = cardNumber.slice(-4);
33

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

Sprint-1/2-mandatory-errors/4.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
const 12HourClockTime = "8:53pm";
2-
const 24hourClockTime = "20:53";
1+
const twelveHourClockTime = "8:53pm";
2+
const twentyFourhourClockTime = "20:53";

Sprint-1/3-mandatory-interpret/1-percentage-change.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ let carPrice = "10,000";
22
let priceAfterOneYear = "8,543";
33

44
carPrice = Number(carPrice.replaceAll(",", ""));
5-
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
5+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
66

77
const priceDifference = carPrice - priceAfterOneYear;
88
const percentageChange = (priceDifference / carPrice) * 100;

Sprint-1/3-mandatory-interpret/2-time-format.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,25 @@ console.log(result);
1212
// For the piece of code above, read the code and then answer the following questions
1313

1414
// a) How many variable declarations are there in this program?
15+
// Answer: 6
1516

1617
// b) How many function calls are there?
18+
// Answer: 1 (console.log(result))
1719

1820
// c) Using documentation, explain what the expression movieLength % 60 represents
1921
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
22+
// Answer: It returns the remainder after movieLength is divided by 60.
23+
// This gives the number of seconds left over after converting to minutes.
2024

2125
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
26+
// Answer: It subtracts the remaining seconds from the total seconds,
27+
// then divides by 60 to calculate the total whole minutes.
2228

2329
// e) What do you think the variable result represents? Can you think of a better name for this variable?
30+
// Answer: It represents the movie duration in hours:minutes:seconds.
31+
// A better name could be formattedTime or movieDuration.
2432

2533
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
34+
// Answer: It works for most values, but it does not always display
35+
// the time in the standard format because single-digit minutes or
36+
// seconds are not padded with a leading zero (for example, 5 instead of 05).

Sprint-1/3-mandatory-interpret/3-to-pounds.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,21 @@ console.log(`£${pounds}.${pence}`);
2525

2626
// To begin, we can start with
2727
// 1. const penceString = "399p": initialises a string variable with the value "399p"
28+
29+
// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1):
30+
// Removes the "p" from the end of the string, leaving only the number (e.g. "399").
31+
32+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"):
33+
// Ensures the number has at least 3 digits by adding leading zeros if necessary.
34+
// For example, "5" becomes "005".
35+
36+
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2):
37+
// Takes all but the last two digits to get the pounds part.
38+
39+
// 5. const pence = paddedPenceNumberString
40+
// .substring(paddedPenceNumberString.length - 2)
41+
// .padEnd(2, "0"):
42+
// Takes the last two digits as the pence part and makes sure it has two digits.
43+
44+
// 6. console.log(`£${pounds}.${pence}`):
45+
// Prints the final price in pounds and pence, for example "£3.99".

0 commit comments

Comments
 (0)