Skip to content

Commit bfedae0

Browse files
authored
identifying error in file 1 and 2 and correct it
1 parent 2c22109 commit bfedae0

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,29 @@
22

33
// Why will an error occur when this program runs?
44
// =============> write your prediction here
5+
// This code is tend to be a code to convert decimal number in to %. I predict there will be an error because the call for the function has a bug.
56

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

8-
function convertToPercentage(decimalNumber) {
9+
/*function convertToPercentage(decimalNumber) {
910
const decimalNumber = 0.5;
1011
const percentage = `${decimalNumber * 100}%`;
1112
1213
return percentage;
13-
}
14+
}/
1415
15-
console.log(decimalNumber);
16+
console.log(decimalNumber);*/
1617

1718
// =============> write your explanation here
19+
// A syntaxError has been observed because the decimalNumber is already declared.
20+
// if we delete line 10 anther error happen this time about calling the function in which decimalNumber is not defined in the global scope.
1821

1922
// Finally, correct the code to fix the problem
2023
// =============> write your new code here
24+
function convertToPercentage(decimalNumber) {
25+
const percentage = `${decimalNumber * 100}%`;
26+
27+
return percentage;
28+
}
29+
30+
console.log(convertToPercentage("0.5"));

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,26 @@
44
// this function should square any number but instead we're going to get an error
55

66
// =============> write your prediction of the error here
7+
/* There is a problem in the function parameter. we can not use number in parameter.
8+
even though line 12 by it self has no coding problem but the num is not declared before.*/
79

10+
/*
811
function square(3) {
912
return num * num;
1013
}
14+
*/
1115

1216
// =============> write the error message here
13-
17+
/* unexpected number
1418
// =============> explain this error message here
19+
we can not use number in a parameter so 3 is not used as identifier */
1520

1621
// Finally, correct the code to fix the problem
1722

1823
// =============> write your new code here
24+
function square(num) {
25+
return num * num;
26+
}
27+
console.log(square("3"))
1928

2029

Sprint-2/2-mandatory-debug/0.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
// Predict and explain first...
22

33
// =============> write your prediction here
4+
/*the function doesn't return any thing so there will be an error. */
45

5-
function multiply(a, b) {
6+
/*function multiply(a, b) {
67
console.log(a * b);
78
}
89
9-
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
10+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);*/
1011

1112
// =============> write your explanation here
13+
/* As predicted the function does not return any thing. But the first call gives 320. and the second undefine. */
1214

1315
// Finally, correct the code to fix the problem
1416
// =============> write your new code here
17+
function multiply(a, b) {
18+
return a * b;
19+
}
20+
21+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

0 commit comments

Comments
 (0)