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 1- 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?
1+ // 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?
3+
4+ // the answer: by using "//" on each line
Original file line number Diff line number Diff line change 11// trying to create an age variable and then reassign the value by 1
22
3- const age = 33 ;
3+ // const age = 33;
4+ // age = age + 1;
5+
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
9+
10+ let age = 33 ;
411age = age + 1 ;
12+ console . log ( age ) ;
Original file line number Diff line number Diff line change 11// Currently trying to print the string "I was born in Bolton" but it isn't working...
22// what's the error ?
33
4- console . log ( `I was born in ${ cityOfBirth } ` ) ;
4+ // console.log(`I was born in ${cityOfBirth}`);
5+ // const cityOfBirth = "Bolton";
6+
7+ // an error in line 4, "ReferenceError: Cannot access 'cityOfBirth' before initialization", which proves my assumption that
8+ // the value of cityOfBirth should have been assigned prior to trying to print the string
9+
510const cityOfBirth = "Bolton" ;
11+ console . log ( `I was born in ${ cityOfBirth } ` ) ;
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)
Original file line number Diff line number Diff line change 1- const 12 HourClockTime = "8:53pm" ;
2- const 24 hourClockTime = "20:53" ;
1+ // const 12HourClockTime = "8:53pm";
2+ // const 24hourClockTime = "20:53";
3+
4+ // SyntaxError: Invalid or unexpected token.
5+ // it turns out that in JS variable names cannot begin with a number
6+
7+ const HourClockTime12 = "8:53pm" ;
8+ const HourClockTime24 = "20:53" ;
9+ console . log ( HourClockTime24 ) ;
You can’t perform that action at this time.
0 commit comments