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
//The % symbol is called the modulus operator. It returns the remainder of a division operation.
29
-
// In this case, movieLength % 60 calculates the remaining seconds after dividing the total movie length by 60 (the number of seconds in a minute).
30
-
// This gives us the number of seconds that do not make up a full minute in the movie length.
29
+
/* In this case, movieLength % 60 calculates the remaining seconds after dividing the total movie length by 60 (the number of seconds in a minute).
30
+
This gives us the number of seconds that do not make up a full minute in the movie length.*/
31
31
32
32
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
33
-
// The expression (movieLength - remainingSeconds) / 60 calculates the total number of minutes in the movie by subtracting the remaining seconds from the total seconds
34
-
// and then dividing by 60.
33
+
/* The expression (movieLength - remainingSeconds) / 60 calculates the total number of minutes in the movie by subtracting the remaining seconds from the total seconds
34
+
and then dividing by 60.*/
35
35
36
36
// e) What do you think the variable result represents? Can you think of a better name for this variable?
37
37
// The variable result represents the formatted time of the movie in hours, minutes, and seconds. A better name for this variable could be movieDuration.
38
38
39
39
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
40
40
//It will do the math perfectly for most normal positive numbers, but there are a few situations where the code will act wierdly.
41
-
//1. The "Single Digit" Visual Bug (Zero-Padding)
42
-
//2. Negative numbers
43
-
//3.Decimal numbers (floats and non integers)
44
-
//4. invalid data types (like strings, objects, etc.)
41
+
/* 1. The "Single Digit" Visual Bug (Zero-Padding)
42
+
2. Negative numbers
43
+
3.Decimal numbers (floats and non integers)
44
+
4. invalid data types (like strings, objects, etc.) */
// 1. const penceString = "399p": initialises a string variable with the value "399p"
28
28
29
29
// 2. const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1): This removes the letter 'p' from the end of the string,
30
-
// leaving just the numbers part of the string. The substring method is used to extract a portion of the string,
31
-
// starting from index 0 and ending at the second-to-last character (length - 1).
30
+
/* leaving just the numbers part of the string. The substring method is used to extract a portion of the string,
31
+
starting from index 0 and ending at the second-to-last character (length - 1). */
32
32
33
33
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); This is to ensure the numbers presented after the substring is at least 3 characters long,
34
34
// if the number is shorter the computer would add '0' or '0's in front of the number to make it 3 digits long.
// This extracts the pence part of the string by taking the last two characters and ensures that it is at least 2 characters long by adding '0' at the end
41
-
// if necessary as this is because we need the decimal value.
40
+
/* This extracts the pence part of the string by taking the last two characters and ensures that it is at least 2 characters long by adding '0' at the end
41
+
if necessary as this is because we need the decimal value. */
42
42
43
43
// 6. console.log(`£${pounds}.${pence}`): This outputs the final answer in the format of pounds and allows the user to see the final result also.
0 commit comments