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
+3-5Lines changed: 3 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -2,21 +2,19 @@
2
2
3
3
// Why will an error occur when this program runs?
4
4
// =============> write your prediction here
5
-
//decimalNumber does not exist outside the scope of the convertToPercentage funtion so the log will throw an error saying it has not been declared.
6
5
7
6
// Try playing computer with the example to work out what is going on
8
7
9
8
functionconvertToPercentage(decimalNumber){
10
-
//const decimalNumber = 0.5;
9
+
constdecimalNumber=0.5;
11
10
constpercentage=`${decimalNumber*100}%`;
12
11
13
12
returnpercentage;
14
13
}
15
14
16
-
console.log(convertToPercentage(0.5));
15
+
console.log(decimalNumber);
17
16
18
17
// =============> write your explanation here
19
-
//decimalNumber is passed as a parameter when the function is called, line 10 tries to declare it again and assign it a new fixed value. we would need to remove that line so we can use the value passed in with the function call.
20
-
//decimalNumber only exists inside the function scope so console.log cannot access it an error will be thrown. we need to instead pass the function to console.log.
0 commit comments