Skip to content

Commit e071e69

Browse files
committed
complete ex 1.js
1 parent c85f975 commit e071e69

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

  • Sprint-3/1-key-errors

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

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

33
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
4+
// =============>// I predict a SyntaxError because decimalNumber is declared as a parameter and then declared again with const.
55

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

8-
function convertToPercentage(decimalNumber) {
8+
/*function convertToPercentage(decimalNumber) {
99
const decimalNumber = 0.5;
1010
const percentage = `${decimalNumber * 100}%`;
1111
1212
return percentage;
1313
}
1414
15-
console.log(decimalNumber);
15+
console.log(decimalNumber);*/
1616

17-
// =============> write your explanation here
17+
/* =============> decimalNumber is already the function parameter.
18+
const decimalNumber tries to declare the same name again inside the function,
19+
so JavaScript gives a SyntaxError. */
1820

1921
// Finally, correct the code to fix the problem
2022
// =============> write your new code here
23+
function convertToPercentage(decimalNumber) {
24+
const percentage = `${decimalNumber * 100}%`;
25+
26+
return percentage;
27+
}
28+
29+
console.log(convertToPercentage(0.5));

0 commit comments

Comments
 (0)