Skip to content

Commit d14a965

Browse files
Apply changes commentd by the reviewer
1 parent 3809119 commit d14a965

File tree

6 files changed

+23
-9
lines changed

6 files changed

+23
-9
lines changed

Sprint-1/1-key-exercises/4-random.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
1010

1111
console.log(num);
1212

13-
// minimum <= num => maximum
13+
// num is a random number between 1 and 100(inclusive)
14+
// using Math.random which returns a number between 0(inclusive) and 1(exclusive)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
// This is just an instruction for the first activity - but it is just for human consumption
22
// We don't want the computer to run these 2 lines - how can we solve this problem?
3+
4+
// running the code throws error because it is written in human language for human understanding
5+
// so it must be commented

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

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

3-
let age = 33;
4-
age = 1;
3+
const age = 33;
4+
age = age + 1;
5+
6+
// TypeError: Assignment to constant variable.
7+
// JS throws above error because the variable age is declared as a constant
8+
// and can not be reassigned.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
22
// what's the error ?
33

4-
const cityOfBirth = "Bolton";
54
console.log(`I was born in ${cityOfBirth}`);
5+
const cityOfBirth = "Bolton";
6+
7+
// cityOfBirth is declared before initialization
8+
// so JS can not access it

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const cardNumber = 4533787178994213;
2-
const last4Digits = String(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
@@ -8,5 +8,8 @@ const last4Digits = String(cardNumber).slice(-4);
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
1010

11-
// slice is a string method but cardNumber is a number
12-
console.log(Number(last4Digits));
11+
// the code will throw error because slice is a string method
12+
// and not a Number method
13+
14+
// TypeError: cardNumber.slice is not a function
15+
// my prediction was correct

Sprint-1/3-mandatory-interpret/1-percentage-change.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ console.log(`The percentage change is ${percentageChange}`);
1212
// Read the code and then answer the questions below
1313

1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
15-
// 4
15+
// 5 times (called on lines: 4, 4, 5, 5, 10 )
1616

1717
// b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem?
1818
// Line 5. It is a syntaxError. string.replaceAll() is missing a ','

0 commit comments

Comments
 (0)