Skip to content

Commit 2bf3487

Browse files
committed
Fix undefined return in sum() and explain cause (2-mandatory-debug/0.js
1 parent 8a162e3 commit 2bf3487

File tree

1 file changed

+9
-3
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+9
-3
lines changed

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

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

33
// =============> write your prediction here
4-
4+
// It will show a undefined error
55
function multiply(a, b) {
66
console.log(a * b);
77
}
88

9-
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
9+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}
1010
1111
// =============> write your explanation here
12-
12+
// The function printed the answer but did't return it, so when it was used in the template string, it came out as 'undefined.'
1313
// Finally, correct the code to fix the problem
1414
// =============> write your new code here
15+
function multiply(a, b) {
16+
return a * b; // Once I put a * b on the same line as return, it worked
17+
}
18+
19+
console.log(` The sum of 10 and 32 is ${sum(10, 32)}`);
20+

0 commit comments

Comments
 (0)