Skip to content

Commit 2f9d4da

Browse files
committed
Return value from multiply function instead of just logging it
1 parent 335cc37 commit 2f9d4da

File tree

1 file changed

+14
-0
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+14
-0
lines changed

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

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

33
// =============> write your prediction here
4+
// I predict that the console will log `320` first (from inside the function),
5+
// but then the message will say: "The result of multiplying 10 and 32 is undefined".
6+
7+
// Explanation:
48

59
function multiply(a, b) {
610
console.log(a * b);
@@ -9,6 +13,16 @@ function multiply(a, b) {
913
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1014

1115
// =============> write your explanation here
16+
// The function `multiply` logs the result of `a * b`, but does not return it.
17+
// When it's used inside a template literal, JavaScript evaluates `multiply(10, 32)` as `undefined`,
18+
// because the function has no return value. That's why we get:
19+
// `The result of multiplying 10 and 32 is undefined` — even though `320` is logged separately.
1220

1321
// Finally, correct the code to fix the problem
1422
// =============> write your new code here
23+
24+
function multiply(a, b) {
25+
return a * b;
26+
}
27+
28+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

0 commit comments

Comments
 (0)