File tree Expand file tree Collapse file tree
Sprint-2/2-mandatory-errors Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11// This is just an instruction for the first activity - but it is just for human consumption
2- // We don't want the computer to run these 2 lines - how can we solve this problem?
2+ // We don't want the computer to run these 2 lines - how can we solve this problem?
3+
4+ // the answer: by using "//" on each line
Original file line number Diff line number Diff line change 33const age = 33 ;
44age = age + 1 ;
55
6- // the error is in line 4. It's a "TypeError: Assignment to constant variable", which happened because the value to
7- // a constant can only be assigned once (as it's )
6+ // the error is in line 4. It's a "TypeError: Assignment to constant variable", which was thrown because the value to
7+ // a specific constant can only be assigned once (which is done in line 3 already).
8+ // This wouldn't throw an error if instead of const, the let was used
Original file line number Diff line number Diff line change 1- const cardNumber = 4533787178994213 ;
1+ const cardNumber = "4533787178994213" ;
2+ //const last4Digits = cardNumber.slice(-4);
23const last4Digits = cardNumber . slice ( - 4 ) ;
4+ console . log ( last4Digits ) ;
35
46// The last4Digits variable should store the last 4 digits of cardNumber
57// However, the code isn't working
68// Before running the code, make and explain a prediction about why the code won't work
79// Then run the code and see what error it gives.
810// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
911// Then try updating the expression last4Digits is assigned to, in order to get the correct value
12+
13+ // I thought it was something to do with the slice "-4" (but i turned out i forgot that negative indices start at -1, not 0)
14+ // The actual error indicates that on the 3rd line there is a typeError: "cardNumber.slice is not a function"
15+ // Checked the error reference and decided to look more closely. Noticed that the card number is used as a number,
16+ // so it answers why the function couldn't be called - because they can be only called on Arrays and Strings.
17+ // Therefore, I'll add parentheses to turn the card number into a string (so that the function could be called)
18+
Original file line number Diff line number Diff line change 11const 12 HourClockTime = "8:53pm" ;
22const 24 hourClockTime = "20:53" ;
3+
4+ console . log ( HourClockTime24 )
5+ // SyntaxError: Invalid or unexpected token.
6+ // it turns out that in JS variable names cannot begin with a number
7+
8+ const HourClockTime12 = "8:53pm" ;
9+ const HourClockTime24 = "20:53" ;
10+ console . log ( HourClockTime24 )
You can’t perform that action at this time.
0 commit comments