Skip to content

Commit 5ab6322

Browse files
committed
removed line 10 and passed function to console
1 parent 26fd354 commit 5ab6322

File tree

1 file changed

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

1 file changed

+5
-3
lines changed

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

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

33
// Why will an error occur when this program runs?
44
// =============> write your prediction here
5+
//decimalNumber does not exist outside the scope of the convertToPercentage funtion so the log will throw an error saying it has not been declared.
56

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

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

1213
return percentage;
1314
}
1415

15-
console.log(decimalNumber);
16+
console.log(convertToPercentage(0.5));
1617

1718
// =============> write your explanation here
18-
19+
//decimalNumber is passed as a parameter when the function is called, line 10 tries to declare it again and assign it a new fixed value. we would need to remove that line so we can use the value passed in with the function call.
20+
//decimalNumber only exists inside the function scope so console.log cannot access it an error will be thrown. we need to instead pass the function to console.log.
1921
// Finally, correct the code to fix the problem
2022
// =============> write your new code here

0 commit comments

Comments
 (0)