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
Copy file name to clipboardExpand all lines: Sprint-2/1-key-errors/1.js
+14-1Lines changed: 14 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -2,19 +2,32 @@
2
2
3
3
// Why will an error occur when this program runs?
4
4
// =============> write your prediction here
5
+
// I expect a Syntax error to be thrown due to the const "decimalNumber" has already been declaired in the parameters of the function.
6
+
// I also expect an error from the "console.log(decimalnumber)" as its calling "decimalNumber" from outside the function
5
7
6
8
// Try playing computer with the example to work out what is going on
7
9
10
+
/*
8
11
function convertToPercentage(decimalNumber) {
9
12
const decimalNumber = 0.5;
10
13
const percentage = `${decimalNumber * 100}%`;
11
14
12
15
return percentage;
13
16
}
14
17
15
-
console.log(decimalNumber);
18
+
console.log(decimalNumber);
19
+
*/
16
20
17
21
// =============> write your explanation here
22
+
// When running the code i get thrown a Syntax error: "identifer 'decimalNumber' has already been declared". To solve this you must remove the "const decimalNumber = 0.5" from the function as its already been defined in the parameters of the function.
23
+
// after testing the code and fixing the syntax error we then recived another error: "ReferenceError: decimalNumber is not defined" To solve this you must change the "console.log(decimalNumber)" to "console.log(convertToPercentage())".
18
24
19
25
// Finally, correct the code to fix the problem
20
26
// =============> write your new code here
27
+
28
+
functionconvertToPercentage(decimalNumber){
29
+
constpercentage=`${decimalNumber*100}%`;
30
+
returnpercentage;
31
+
}
32
+
33
+
console.log(convertToPercentage(0.5));// equals to 50%
0 commit comments