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 11This 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+ //We have to use the // to comment a single line
5+ /* or use /* to comment multiple lines */
Original file line number Diff line number Diff line change 22
33const age = 33 ;
44age = age + 1 ;
5+ /* const means that the variable cannot be reassigned we should use let keyword instead.
6+ TypeError displayed due to that. */
Original file line number Diff line number Diff line change 33
44console . log ( `I was born in ${ cityOfBirth } ` ) ;
55const cityOfBirth = "Bolton" ;
6+
7+ //The error we see it's a ReferenceError which tells us that we cannot access variable before initialization.
8+
9+ /*JavaScript reads the code from top to bottom, order is wrong.
10+ Task cannot be executed as variable cannot be access before being created. */
Original file line number Diff line number Diff line change 11const cardNumber = 4533787178994213 ;
2- const last4Digits = cardNumber . slice ( - 4 ) ;
2+ const last4Digits = cardNumber . toString ( ) . slice ( - 4 ) ;
3+ console . log ( last4Digits ) ;
34
45// The last4Digits variable should store the last 4 digits of cardNumber
56// However, the code isn't working
67// Before running the code, make and explain a prediction about why the code won't work
78// Then run the code and see what error it gives.
89// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
910// Then try updating the expression last4Digits is assigned to, in order to get the correct value
11+
12+
13+ /*The code would not work because cardNumber variable stores number data type and .slice() method cannot be used on a number,
14+ if we run the code without changing data type to string we will get TypeError displayed
15+ I used .toString() method to convert cardNumber variable to a string and then used .slice(-4) to get the last 4 digits. */
Original file line number Diff line number Diff line change 11const 12 HourClockTime = "8:53pm" ;
22const 24 hourClockTime = "20:53" ;
3+
4+ //A variable cannot start with a number, SyntaxError is displayed.
You can’t perform that action at this time.
0 commit comments