-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.js
More file actions
19 lines (12 loc) · 646 Bytes
/
Copy path1.js
File metadata and controls
19 lines (12 loc) · 646 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Predict and explain first...
// Why will an error occur when this program runs?
// =============> An error will occur because console.log(decimalNumber) tries to access a variable that does not exist in the global scope.
// Try playing computer with the example to work out what is going on
// =============> decimalNumber is already a parameter, and JavaScript does not allow redeclaring a parameter woth const.
// Finally, correct the code to fix the problem
// =============>
function convertToPercentage(decimalNumber) {
const percentage = `${decimalNumber * 100}%`;
return percentage;
}
console.log(convertToPercentage(0.5));