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
predicted the the program will not work because the function will not return a value and changed the console.log inside the function into return instead.
Copy file name to clipboardExpand all lines: Sprint-2/2-mandatory-debug/0.js
+17Lines changed: 17 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
1
// Predict and explain first...
2
2
3
3
// =============> write your prediction here
4
+
// I prediact that the error will occur because the function multiply does not return any value and this will make the console.log function to print undefined instead.
5
+
4
6
5
7
functionmultiply(a,b){
6
8
console.log(a*b);
@@ -9,6 +11,21 @@ function multiply(a, b) {
9
11
console.log(`The result of multiplying 10 and 32 is ${multiply(10,32)}`);
10
12
11
13
// =============> write your explanation here
14
+
// when the program run it give this output:
15
+
16
+
// 320
17
+
// The result of multiplying 10 and 32 is undefined
18
+
19
+
// 320: the out put for the console.log inside the function
20
+
21
+
// while the ouout the out put for the console.log function out of the function returned the string provided in the function and an undefiened because the function multibly doesn't return any value.
22
+
// to fix this error we need to change the console.log function inside the function to return.
23
+
12
24
13
25
// Finally, correct the code to fix the problem
14
26
// =============> write your new code here
27
+
functionmultiply(a,b){
28
+
returna*b;
29
+
}
30
+
31
+
console.log(`The result of multiplying 10 and 32 is ${multiply(10,32)}`);
0 commit comments