File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33let age = 33 ;
44age = age + 1 ;
5+
6+ // The original code used const to declare age.
7+ // A const variable cannot be reassigned after declaration.
8+ // Attempting to reassign age caused a TypeError.
9+ // Changing const to let fixes the problem because let allows reassignment.
Original file line number Diff line number Diff line change 33
44const cityOfBirth = "Bolton" ;
55console . log ( `I was born in ${ cityOfBirth } ` ) ;
6+
7+ // The original code tried to use cityOfBirth before it was initialized.
8+ // This caused a ReferenceError because variables declared with const
9+ // cannot be accessed before their declaration.
10+ // Moving the declaration before console.log fixes the problem.
Original file line number Diff line number Diff line change @@ -7,3 +7,14 @@ const last4Digits = cardNumber.toString().slice(-4);
77// Then run the code and see what error it gives.
88// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
99// Then try updating the expression last4Digits is assigned to, in order to get the correct value
10+
11+ // Prediction: I expected the code to fail because cardNumber
12+ // is a number, and slice() is a string method.
13+ //
14+ // Actual result: The original code produced a TypeError
15+ // because cardNumber.slice is not a function.
16+ //
17+ // The fix converts cardNumber into a string using toString()
18+ // before calling slice(-4) to extract the last four digits.
19+ //
20+ // The actual error matched my prediction.
Original file line number Diff line number Diff line change 11const twelveHourClockTime = "8:53pm" ;
22const twentyFourHourClockTime = "20:53" ;
3+
4+ // The original variable names started with numbers.
5+ // JavaScript variable names cannot begin with a number.
6+ // This caused a SyntaxError because the names were invalid.
7+ // Renaming the variables to start with letters fixes the problem.
Original file line number Diff line number Diff line change 1- const movieLength = 8784 ; // length of movie in seconds
1+ const movieLength = 90.5 ;
22
33const remainingSeconds = movieLength % 60 ;
44const totalMinutes = ( movieLength - remainingSeconds ) / 60 ;
@@ -31,5 +31,16 @@ console.log(result);
3131// A better variable name would be formattedMovieLength.
3232
3333// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
34- // Answer: No, it will not format all values correctly.
35- // For example, single-digit minutes or seconds will not have a leading zero.
34+ // // Answer: No, the code does not work correctly for all values.
35+ //
36+ // Testing -90 produced 0:-1:-30, which is not a valid time format.
37+ // Negative durations should not be accepted.
38+ //
39+ // Testing 90.5 produced 0:1:30.5, showing that the program
40+ // does not handle fractional seconds appropriately.
41+ //
42+ // The program also does not add leading zeros to single-digit
43+ // minutes or seconds.
44+ //
45+ // The program should validate its input and format the
46+ // output correctly.
You can’t perform that action at this time.
0 commit comments