Skip to content

Commit 2cb2539

Browse files
Delete and cons and put convertToPercentage function back in the code
1 parent 450b81e commit 2cb2539

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

  • Sprint-3/1-key-errors

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

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

33
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
4+
// =============> I think when we run the programme it will show the type error because decimal number is reassigning inside the function.
55

66
// Try playing computer with the example to work out what is going on
77

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

12-
return percentage;
13-
}
12+
// return percentage;
13+
// }
1414

15-
console.log(decimalNumber);
15+
// console.log(decimalNumber);
1616

1717
// =============> write your explanation here
18-
18+
// while running this function is shows typeerror because decimal number variable is declared two times.
19+
// and in step 15 we need call function name not decimal number.
1920
// Finally, correct the code to fix the problem
2021
// =============> write your new code here
22+
function convertToPercentage(decimalNumber) {
23+
24+
const percentage = `${decimalNumber * 100}%`;
25+
26+
return percentage;
27+
}
28+
29+
console.log(convertToPercentage(0.5));
30+
// After solving this the output is 50%.

0 commit comments

Comments
 (0)