Skip to content

Commit 5666561

Browse files
committed
key errors part is finished
1 parent f6d89d1 commit 5666561

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Predict and explain first...
2+
// program is made for converting a decimal number into a percentage.
23

34
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
5+
// =============> I think error would occur because decimalNumber is declared twice.
56

67
// Try playing computer with the example to work out what is going on
78

@@ -14,7 +15,15 @@ function convertToPercentage(decimalNumber) {
1415

1516
console.log(decimalNumber);
1617

17-
// =============> write your explanation here
18+
// =============> to fix the problem I will remove the second declaration of decimalNumber and use the parameter instead.
1819

1920
// Finally, correct the code to fix the problem
20-
// =============> write your new code here
21+
// =============>
22+
function convertToPercentage(decimalNumber) {
23+
const percentage = `${decimalNumber * 100}%`;
24+
25+
return percentage;
26+
}
27+
28+
// to call the function
29+
console.log(convertToPercentage(1)); // Output: "100%"

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,24 @@
33

44
// this function should square any number but instead we're going to get an error
55

6-
// =============> write your prediction of the error here
6+
// =============> My prediction is that error occurs because function trying to use a number as a function.
77

88
function square(3) {
99
return num * num;
1010
}
1111

12-
// =============> write the error message here
12+
// =============> Expected identifier but found "3"
1313

14-
// =============> explain this error message here
14+
// =============> While program waiting for an identifier, it found a number instead.
1515

1616
// Finally, correct the code to fix the problem
1717

18-
// =============> write your new code here
18+
// =============>
19+
function square(num) {
20+
return num * num;
21+
}
22+
23+
// to call the function
24+
console.log(square(9)); // Output: 81
1925

2026

0 commit comments

Comments
 (0)