-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.js
More file actions
28 lines (22 loc) · 968 Bytes
/
Copy path1.js
File metadata and controls
28 lines (22 loc) · 968 Bytes
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...
// Why will an error occur when this program runs?
// =============> write your prediction here
// They have used the same variable name twice. This will cause an error. Also line 9 is not needed because the function takes a decimal as an argument.
// Try playing computer with the example to work out what is going on
function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;
const percentage = `${decimalNumber * 100}%`;
return percentage;
}
console.log(decimalNumber);
// =============> write your explanation here
// SyntaxError: Identifier 'decimalNumber' has already been declared.
// ReferenceError: decimalNumber is not defined
// Finally, correct the code to fix the problem
// =============> write your new code here
function convertToPercentage(decimalNumber) {
const percentage = `${decimalNumber * 100}%`;
console.log("percentage",percentage)
return percentage;
}
convertToPercentage(0.8)