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
+11-3Lines changed: 11 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
// Why will an error occur when this program runs?
4
4
// =============> write your prediction here
5
-
5
+
// My prediction is that the variable `decimalNumber` is already declared and also the console.log can only log the variable decimalNumber.
6
6
// Try playing computer with the example to work out what is going on
7
7
8
8
functionconvertToPercentage(decimalNumber){
@@ -14,7 +14,15 @@ function convertToPercentage(decimalNumber) {
14
14
15
15
console.log(decimalNumber);
16
16
17
-
// =============> write your explanation here
17
+
// =============> write your explanation here: the variable was already declared in the parameter scope and it won't redeclare inside the function again
18
+
// and also the console.log was only working for the logging of the variable `decimalNumber` not the function.
18
19
19
20
// Finally, correct the code to fix the problem
20
-
// =============> write your new code here
21
+
// =============> write your new code here: const decimalNumber = 0.5;
// =============> write your prediction here: My prediction is that in this function there is two console.log
4
+
// the result of this two log will print one with the value only 320 and
5
+
// the other one with the sentences of the log not the value.
4
6
5
7
functionmultiply(a,b){
6
8
console.log(a*b);
7
9
}
8
10
9
11
console.log(`The result of multiplying 10 and 32 is ${multiply(10,32)}`);
10
12
11
-
// =============> write your explanation here
13
+
// =============> write your explanation here: because of the log inside the function the outside function can't access the result so the log will print
14
+
// one with the value only and second console.log will print the sentences with explanation of the result and
15
+
// undefined value because the the function doesn't access the operation.
12
16
13
17
// Finally, correct the code to fix the problem
14
-
// =============> write your new code here
18
+
// =============> write your new code here: function multiply(a, b) {
19
+
// return a * b;
20
+
// }
21
+
22
+
// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
0 commit comments