Skip to content

Commit 818acf9

Browse files
committed
completed 3.js with comments also commented out question in 1.js and 2.js
1 parent 8348eb6 commit 818acf9

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
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.
99
let age = 33;
1010
age = age + 1;
11+
console.log(age);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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

1111
const cityOfBirth = "Bolton";
1212
console.log(`I was born in ${cityOfBirth}`);

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
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);

0 commit comments

Comments
 (0)