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
// % is the remainder. that line of code divides the total seconds number by 60 and gives us the remaining seconds.
26
+
21
27
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
22
28
29
+
// in this line, totalMinutes of the move calculated. the remainder will be deducted and the rest of the second divided by 60 gives us the total minutes number.
30
+
31
+
23
32
// e) What do you think the variable result represents? Can you think of a better name for this variable?
24
33
34
+
// it represents the move length in hour, minutes and seconds. and it would be better understood as duration.
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
+
// yes as long as it receives the total seconds as a whole number it works fine.
// 1. const penceString = "399p": initialises a string variable with the value "399p"
17
+
// 2. const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1): creates a new string with the last character removed by taking a substring from index 0 up to
18
+
// penceString.length - 1, it removes the trailing "p" so we are left with the numeric pence portion as a string.
19
+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): ensures the numeric string has at least 3 characters by adding leading zeros if required.
20
+
// padStart(3, "0") will left-pad with "0" until the length is at least 3, so the code expects to split the string into ...pounds and last two digits = pence.
21
+
// By guaranteeing at least 3 characters, the substring operations that follow always have at least one digit for pounds and two for pence.
22
+
// 4. const pounds = paddedPenceNumberString.substring( 0 , paddedPenceNumberString.length - 2): takes the substring from the start up to the character two from the end.
23
+
// That is, everything except the last two characters. as the last two characters represent pence; everything before that is pounds. Splitting this way converts a string of
24
+
// pure pence into pounds and pence parts.
25
+
// 5. substring(paddedPenceNumberString.length - 2): takes the last two characters (the pence portion).
26
+
// 6. .padEnd(2, "0"): would add trailing zeros to make sure the pence string is at least 2 characters long.
0 commit comments