Skip to content

Commit 142dcbd

Browse files
solving exercise 0.1
1 parent ca30eb5 commit 142dcbd

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

  • Sprint-3/1-key-errors

‎Sprint-3/1-key-errors/1.js‎

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

33
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
4+
// =============> write your prediction here D: Answer => variable decimalNumber is declared twice : one time in the parameter and another time inside the function
55

6-
// Try playing computer with the example to work out what is going on
76

87
function convertToPercentage(decimalNumber) {
9-
const decimalNumber = 0.5;
8+
//const decimalNumber = 0.5;
109
const percentage = `${decimalNumber * 100}%`;
1110

1211
return percentage;
@@ -15,6 +14,15 @@ function convertToPercentage(decimalNumber) {
1514
console.log(decimalNumber);
1615

1716
// =============> write your explanation here
18-
17+
// solution :Also in line 15 console.log is trying print a variable which is not defined instead of calling the function convertToPercentage .
1918
// Finally, correct the code to fix the problem
2019
// =============> write your new code here
20+
21+
function convertToPercentage(decimalNumber) {
22+
23+
const percentage = `${decimalNumber * 100}%`;
24+
25+
return percentage;
26+
}
27+
28+
console.log(convertToPercentage(0.5));

0 commit comments

Comments
 (0)