Skip to content

Commit d207836

Browse files
Fix 2-mandatory-debug/0.js: return the product instead of logging it
1 parent 468f39f commit d207836

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

  • Sprint-3/2-mandatory-debug

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

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

33
// =============> write your prediction here
4+
// I predict it will print 320 first (from the console.log inside multiply),
5+
// and then "The result of multiplying 10 and 32 is undefined", because
6+
// multiply does not return a value.
47

58
function multiply(a, b) {
6-
console.log(a * b);
9+
return (a * b);
710
}
811

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

1114
// =============> write your explanation here
15+
// multiply only logs a * b to the console. It has no return statement, so
16+
// multiply(10, 32) evaluates to undefined. The template string on line 12
17+
// puts that undefined into the sentence. The 320 appears on its own line
18+
// because console.log runs inside the function.
1219

1320
// Finally, correct the code to fix the problem
1421
// =============> write your new code here
22+
// I changed console.log(a * b) to return a * b inside multiply, so the
23+
// function hands the result back to the caller instead of only printing it.

0 commit comments

Comments
 (0)