Skip to content

Commit 03db3d4

Browse files
Fix multiply function to return the product
The multiply function now returns the product of a and b, fixing the undefined output issue.
1 parent ee8e2c7 commit 03db3d4

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

  • Sprint-2/2-mandatory-debug

Sprint-2/2-mandatory-debug/0.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
// Predict and explain first...
22

3+
34
// =============> write your prediction here
45

6+
57
function multiply(a, b) {
68
console.log(a * b);
79
}
810

11+
912
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1013

11-
// =============> write your explanation here
14+
15+
// =============> The function is only printing values on the console but not returning the value to the caller. Henceforth, it outputs both 320 and undefined on the console. 320 is the result of the console.log(a * b) inside the function, whereas undefined comes from the outer console.log(...) as it tries to bring forth and print the result of the function multiply(a, b). But the function is not returning any value and hence undefined appears on the console.
16+
1217

1318
// Finally, correct the code to fix the problem
14-
// =============> write your new code here
19+
/* =============> function multiply(a, b) {
20+
return a * b;
21+
}
22+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
23+

0 commit comments

Comments
 (0)