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
{{ message }}
Repository navigation
Commit 3b49e4d
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: Sprint-3/1-key-errors/1.js
+12Lines changed: 12 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
2
2
3
3
// Why will an error occur when this program runs?
4
4
// =============> write your prediction here
5
+
// An error will occur because `decimalNumber` is declared twice
6
+
// inside the function: once as a parameter and again using `const`.
5
7
6
8
// Try playing computer with the example to work out what is going on
7
9
@@ -15,6 +17,16 @@ function convertToPercentage(decimalNumber) {
15
17
console.log(decimalNumber);
16
18
17
19
// =============> write your explanation here
20
+
// The function already has a parameter called decimalNumber.
21
+
// The line const decimalNumber = 0.5 tries to declare another variable with the same name in the same scope.
22
+
// JavaScript does not allow this, so a SyntaxError occurs.
23
+
// There is also another problem: decimalNumber only exists inside the function, so console.log(decimalNumber) outside the function would cause a ReferenceError.
0 commit comments