Skip to content

Commit f00caed

Browse files
author
russom
committed
Predict, fix, and explain code
1 parent 1df46e8 commit f00caed

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

  • Sprint-3/1-key-errors

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,32 @@
33
// Why will an error occur when this program runs?
44
// =============> write your prediction here
55

6+
// Prediction:
7+
// 1. decimalNumber is declared twice and it will give syntax error.
8+
69
// Try playing computer with the example to work out what is going on
710

8-
function convertToPercentage(decimalNumber) {
11+
/*function convertToPercentage(decimalNumber) {
912
const decimalNumber = 0.5;
1013
const percentage = `${decimalNumber * 100}%`;
1114
1215
return percentage;
1316
}
1417
15-
console.log(decimalNumber);
18+
console.log(decimalNumber);*/
1619

1720
// =============> write your explanation here
1821

22+
// 2. console.log will return undefined as decimalNumber local scope declaration inside the function.
23+
// 3. It's percentage not decimalNumber needs printing.
24+
1925
// Finally, correct the code to fix the problem
2026
// =============> write your new code here
27+
28+
function convertToPercentage(decimalNumber) {
29+
return percentage = `${decimalNumber * 100}%`;
30+
}
31+
32+
console.log(convertToPercentage(0.5));
33+
34+
// The function convertToPercentage can be called passing with an argument of the input.

0 commit comments

Comments
 (0)