You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Predict and explain first: Decimalnumber is already declared as a parameter of the function convertToPercentage,
2
+
// so when we try to declare it again inside the function, it will give an error.
2
3
3
4
// Why will an error occur when this program runs?
4
-
// =============> write your prediction here
5
+
// =============> 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.
5
6
6
7
// Try playing computer with the example to work out what is going on
7
8
8
9
functionconvertToPercentage(decimalNumber){
9
-
constdecimalNumber=0.5;
10
+
10
11
constpercentage=`${decimalNumber*100}%`;
11
12
12
13
returnpercentage;
13
14
}
14
15
15
-
console.log(decimalNumber);
16
+
console.log(convertToPercentage(0.5));
16
17
17
-
// =============> write your explanation here
18
+
// =============> write your explanation here : I removed the variable variation inside the function and directly calculated the percentage.
18
19
19
20
// Finally, correct the code to fix the problem
20
-
// =============> write your new code here
21
+
// =============> write your new code here :function convertToPercentage(decimalNumber) {
0 commit comments