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
// in this code we have a function called multiply that takes two parameters a and b,
5
+
//inside the function it will print the result of multiplying a and b,
6
+
// but a and b are not defined, not in global scope nor local scope, so we will get error.
7
+
// there is another console log statement that will print a string with the result of multiplying 10 and 32,
8
+
// but the function multiply does not return any value, so the result will be undefined.
9
+
// so the final output will be "The result of multiplying 10 and 32 is undefined"
4
10
5
-
functionmultiply(a,b){
6
-
console.log(a*b);
7
-
}
11
+
// function multiply(a, b) {
12
+
// console.log(a * b);
13
+
// }
8
14
9
-
console.log(`The result of multiplying 10 and 32 is ${multiply(10,32)}`);
15
+
// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
10
16
11
17
// =============> write your explanation here
18
+
// it wasn't completely as I predicted, the first console log statement inside the function multiply did worked and
19
+
// it printed 320, which measn that the function parameters a and b took the values 10 and 32 from the function call multiply(10, 32).
20
+
// but the second console log statement printed "The result of multiplying 10 and 32 is undefined" because the function multiply does not return any value,
21
+
// so the result of multiplying 10 and 32 is undefined.
12
22
13
23
// Finally, correct the code to fix the problem
14
24
// =============> write your new code here
25
+
// I will add a return statement to the function multiply that returns the result of multiplying a and b.
26
+
27
+
functionmultiply(a,b){
28
+
return(a*b);
29
+
}
30
+
31
+
console.log(`The result of multiplying 10 and 32 is ${multiply(10,32)}`);
0 commit comments