-
-
Notifications
You must be signed in to change notification settings - Fork 337
Expand file tree
/
Copy path1.js
More file actions
28 lines (17 loc) · 1.03 KB
/
1.js
File metadata and controls
28 lines (17 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Predict and explain first: Decimalnumber is already declared as a parameter of the function convertToPercentage,
// so when we try to declare it again inside the function, it will give an error.
// Why will an error occur when this program runs?
// =============> write your prediction here : The error will occur because we are trying to declare a variable with the same name as the parameter of the function.
// Try playing computer with the example to work out what is going on
function convertToPercentage(decimalNumber) {
const percentage = `${decimalNumber * 100}%`;
return percentage;
}
console.log(convertToPercentage(0.5));
// =============> write your explanation here : I removed the variable variation inside the function and directly calculated the percentage.
// Finally, correct the code to fix the problem
// =============> write your new code here :function convertToPercentage(decimalNumber) {
// const percentage = `${decimalNumber * 100}%`;
// return percentage;
// }
//console.log(convertToPercentage(0.5));