Skip to content

Commit 6ca5625

Browse files
committed
resolve syntax and reference errors in Sprint-2 > 1-key-errors > 1.js
1 parent b9e9f5c commit 6ca5625

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

  • Sprint-2/1-key-errors

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

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

33
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
4+
// =============> same as before, decimalNumber in the function para, but also as a constant inside the function. also we are trying to log decimalNumber, but thats the input, or inside the function the new variable which would result in a scope issue, since this does not exist outside of the function
55

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

88
function convertToPercentage(decimalNumber) {
9-
const decimalNumber = 0.5;
9+
const decimal = 0.5;
1010
const percentage = `${decimalNumber * 100}%`;
1111

1212
return percentage;
1313
}
1414

1515
console.log(decimalNumber);
1616

17-
// =============> write your explanation here
18-
17+
// =============> Uncaught SyntaxError: Identifier 'decimalNumber' has already been declared - so the same issue as the previous
18+
//also after changing the decimalNumber to decimal inside the function: Uncaught ReferenceError ReferenceError: decimalNumber is not defined -->in console log we should ask for the function
1919
// Finally, correct the code to fix the problem
20-
// =============> write your new code here
20+
// =============>
21+
function convertToPercentage() {
22+
const decimalNumber = 0.5;
23+
const percentage = `${decimalNumber * 100}%`;
24+
25+
return percentage;
26+
}
27+
console.log(convertToPercentage());

0 commit comments

Comments
 (0)