File tree Expand file tree Collapse file tree 3 files changed +23
-7
lines changed
Sprint-1/2-mandatory-errors Expand file tree Collapse file tree 3 files changed +23
-7
lines changed 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 ;
4- age = age + 1 ;
3+ // const age = 33;
4+ // age = age + 1;
55
66//Answer:
77//we cannot re-assign variables with "const".
88// We have use "let". let allows the variable to be re-assigned.
99let age = 33 ;
1010age = age + 1 ;
11+ 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 } ` ) ;
5- const cityOfBirth = "Bolton" ;
4+ // console.log(`I was born in ${cityOfBirth}`);
5+ // const cityOfBirth = "Bolton";
66
77//*Answer
88// The console.log is before the variable and it cannot see it.
9- // The console log needs to be blow the variable to compute the data.
9+ // The console log needs to be below the variable to compute the data.
1010
1111const cityOfBirth = "Bolton" ;
1212console . log ( `I was born in ${ cityOfBirth } ` ) ;
Original file line number Diff line number Diff line change 1- const cardNumber = 4533787178994213 ;
2- const last4Digits = cardNumber . slice ( - 4 ) ;
1+ // const cardNumber = 4533787178994213;
2+ // const last4Digits = cardNumber.slice(-4);
33
44// The last4Digits variable should store the last 4 digits of cardNumber
55// However, the code isn't working
6+
67// Before running the code, make and explain a prediction about why the code won't work
8+ //*Answer
9+ //It won't work because cardNumber is not a string and .slice() only works with strings. It will throw an error.
10+
711// Then run the code and see what error it gives.
12+ //*Answer
13+ //Uncaught TypeError: cardNumber.slice is not a function
14+
815// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
16+ //*Answer
17+ //I was right. cardNumber is a number not a string and .slice() only works with strings
18+ // so it needs to be converted to a string to work using .toString()
19+
920// Then try updating the expression last4Digits is assigned to, in order to get the correct value
21+ //*Answer
22+ const cardNumber = 4533787178994213 ;
23+ const last4Digits = cardNumber . toString ( ) . slice ( - 4 ) ;
24+ console . log ( last4Digits ) ;
You can’t perform that action at this time.
0 commit comments