Skip to content

Commit f47f36b

Browse files
debug2604debug2604
authored andcommitted
1.js result predicted, explained the errors, and wrote new code
1 parent 342efc6 commit f47f36b

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

  • Sprint-3/1-key-errors

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

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

33
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
4+
// =============> SyntaxError will occurs
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}%`;
11-
12-
return percentage;
13-
}
8+
//function convertToPercentage(decimalNumber) {
9+
//const decimalNumber = 0.5;
10+
//const percentage = `${decimalNumber * 100}%`;
1411

15-
console.log(decimalNumber);
12+
//return percentage;
13+
//}
1614

17-
// =============> write your explanation here
15+
//console.log(decimalNumber);
1816

17+
// =============> decimalNumber first declared as parameter, it cannot be reassigned as const.
18+
// Also, console.log try to run decimalNumber as a variable while decimalNumber be assigned as a parameter.
1919
// Finally, correct the code to fix the problem
2020
// =============> write your new code here
21+
function convertToPercentage(decimalNumber) {
22+
const percentage = `${decimalNumber * 100}%`;
23+
24+
return percentage;
25+
}
26+
console.log(convertToPercentage(0.5));

0 commit comments

Comments
 (0)