You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// movieLength % 60 gives the leftover seconds after converting seconds into whole minutes.
26
+
21
27
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
22
28
29
+
//It gets the total minutes by removing the leftover seconds and converting the remaining seconds into minutes by dividing by 60.
30
+
23
31
// e) What do you think the variable result represents? Can you think of a better name for this variable?
24
32
33
+
//remainingMinutes is the minutes part in an hours:minutes:seconds display
34
+
// It can be named as minutesDisplay.
35
+
25
36
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
37
+
38
+
// The code will work for all positive integer values of MovieLength.
39
+
// If movieLength is negative, the code will still run but it will give a negative time which doesn't make sense in this context.
40
+
// If movieLength is not an integer, it will still run but it may give unexpected results due to the way the modulus operator works with non-integer values.
// This makes sure the pence number has at least 3 characters by adding zeros to the front if it’s too short (so "5" would become "005"), and "399" stays "399".
9
15
constpounds=paddedPenceNumberString.substring(
10
16
0,
11
17
paddedPenceNumberString.length-2
12
18
);
13
19
20
+
// This takes everything except the last 2 digits, which gives the pounds part (for "399" it becomes "3").
21
+
14
22
constpence=paddedPenceNumberString
15
23
.substring(paddedPenceNumberString.length-2)
16
24
.padEnd(2,"0");
17
25
18
-
console.log(`£${pounds}.${pence}`);
26
+
//This takes the last 2 digits to get the pence part (for "399" it becomes "99") and ensures it is always 2 digits long by padding with zeros on the right if needed.
19
27
20
-
// This program takes a string representing a price in pence
21
-
// The program then builds up a string representing the price in pounds
28
+
console.log(`£${pounds}.${pence}`);
22
29
23
-
// You need to do a step-by-step breakdown of each line in this program
24
-
// Try and describe the purpose / rationale behind each step
30
+
// This prints the final formatted price by inserting pounds and pence into a template string, producing £3.99.
25
31
26
-
// To begin, we can start with
27
-
// 1. const penceString = "399p": initialises a string variable with the value "399p"
32
+
// This program takes a string representing a price in pence
0 commit comments