Skip to content

Commit 1ccf331

Browse files
committed
completed the 2-mandatory-errors of sprint-1
1 parent f81891c commit 1ccf331

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

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

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
// trying to create an age variable and then reassign the value by 1
22

3-
const age = 33;
3+
/* const age = 33;
44
age = age + 1;
5+
*/
6+
// This code will throw an error because we are trying to reassign a value to a constant variable (age). In JavaScript, once a variable is declared with const, its value cannot be changed. To fix this error, we can either change the declaration to let or var, which allows for reassignment, or we can create a new variable to store the updated age. For example:
7+
8+
let age = 33;
9+
age = age + 1;
10+
console.log(age);

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +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}`);
4+
/*console.log(`I was born in ${cityOfBirth}`);
55
const cityOfBirth = "Bolton";
6+
*/
7+
8+
9+
// The error in this code is that we are trying to use the variable cityOfBirth before it has been declared and assigned a value. In JavaScript, variables declared with const (or let) are not hoisted, which means they cannot be accessed before their declaration. To fix this error, we need to declare and assign a value to cityOfBirth before using it in the console.log statement. For example:
10+
11+
const cityOfBirth = "Bolton";
12+
console.log(`I was born in ${cityOfBirth}`);

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
const cardNumber = 4533787178994213;
1+
/*const cardNumber = 4533787178994213;
22
const last4Digits = cardNumber.slice(-4);
3+
*/
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+
// The code above won't work because cardNumber is a number, and the slice method is a string method. The slice method cannot be used on a number, which will result in a TypeError. To fix this error, we can convert cardNumber to a string before using the slice method. For example:
13+
14+
15+
const cardNumber = 4533787178994213;
16+
const last4Digits = cardNumber.toString().slice(-4);
17+
console.log(last4Digits);

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
const 12HourClockTime = "20:53";
2-
const 24hourClockTime = "08:53";
1+
/*const twelveHourClockTime = "20:53";
2+
const twentyFourHourClockTime = "08:53";
3+
*/
4+
5+
//
6+
// The code above won't work because the variable names suggest that twelveHourClockTime should represent a time in 12-hour format, while twentyFourHourClockTime should represent a time in 24-hour format. However, the values assigned to these variables are not consistent with their names. To fix this error, we can either change the variable names to match the values or update the values to match the variable names. For example:
7+
8+
const twelveHourClockTime = "08:53 PM";
9+
const twentyFourHourClockTime = "20:53";

0 commit comments

Comments
 (0)