Skip to content

Commit f500eb4

Browse files
committed
Address Sprint 2 review feedback
1 parent 770d48e commit f500eb4

5 files changed

Lines changed: 40 additions & 3 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22

33
let age = 33;
44
age = 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.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@
33

44
const cityOfBirth = "Bolton";
55
console.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.

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
const twelveHourClockTime = "8:53pm";
22
const 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.

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const movieLength = 8784; // length of movie in seconds
1+
const movieLength = 90.5;
22

33
const remainingSeconds = movieLength % 60;
44
const 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.

0 commit comments

Comments
 (0)