Skip to content

Commit dca0ac7

Browse files
committed
Predict, Explain and Correct code 1.js
1 parent c9dbc7a commit dca0ac7

File tree

1 file changed

+19
-3
lines changed
  • Sprint-2/1-key-errors

1 file changed

+19
-3
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
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 : The variable decimalNumber has been declared.
55

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

8+
// The old code :
9+
/*
810
function convertToPercentage(decimalNumber) {
911
const decimalNumber = 0.5;
1012
const percentage = `${decimalNumber * 100}%`;
@@ -13,8 +15,22 @@ function convertToPercentage(decimalNumber) {
1315
}
1416
1517
console.log(decimalNumber);
18+
*/
1619

17-
// =============> write your explanation here
18-
20+
// =============> write your explanation here :
21+
/*
22+
-The variable decimalNumber has been declared within the function as a parameter then declared again using const.
23+
- The variable decimalNumber should be defined first.
24+
*/
1925
// Finally, correct the code to fix the problem
2026
// =============> write your new code here
27+
28+
//The correct code :
29+
const decimalNumber = 0.5;
30+
31+
function convertToPercentage(decimalNumber) {
32+
const percentage = `${decimalNumber * 100}%`;
33+
return percentage;
34+
}
35+
36+
console.log(convertToPercentage(decimalNumber));

0 commit comments

Comments
 (0)