Skip to content

Commit 21b7a96

Browse files
committed
Completed 1-key exercies and 2-mandatory-errors
1 parent 3372770 commit 21b7a96

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
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+
//we can solve this by making the above statements as comments using //

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
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 mistake in the above code is the use of const which we use only to save the constant values
7+
which we don't want to change in the future; therefore, in the above example we would declare age
8+
as a variable rather than constant to solve the issue.*/
9+
10+
let age = 33;
411
age = age + 1;
12+
console.log(age);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33

44
console.log(`I was born in ${cityOfBirth}`);
55
const cityOfBirth = "Bolton";
6+
7+
//the above code is not working because you are printing or using the cityOfBirth constant before initializing it

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
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
66
// Before running the code, make and explain a prediction about why the code won't work
77
// Then run the code and see what error it gives.
88
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
99
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
10+
11+
//I predicted that the code is not working because the cardNumber is a constant value and cannot be changed
12+
// but actually we are not changing the value of cardNumber we are just slicing it which will be stored in a different variable
13+
//and the cardNumber value will remain the same
14+
//After running the code, I have realized that the code is not working because cardNumber is a number and the slice is a method in String class
15+
//so, in order to make it work, we need to change cardNumber to String before calling the slice method
16+
17+
const last4Digits = (cardNumber + "").slice(-4);
18+
console.log("Last four digits of card are : " + 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 12HourClockTime = "20:53";
2+
//const 24hourClockTime = "08:53";
3+
4+
const twelveHourClockTime = "20:53";
5+
const twentyFourhourClockTime = "08:53";
6+
7+
/*in javascript and also many other programming languages, we can't start the name of an identifier
8+
// with a number, therefore, I have changed that to text form*/
9+

0 commit comments

Comments
 (0)