Skip to content

Commit 2ff3562

Browse files
Fix multiply function to return value instead of logging
1 parent 245e73e commit 2ff3562

File tree

1 file changed

+26
-1
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+26
-1
lines changed

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

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

33
// =============> write your prediction here
4+
// The function multiplies the numbers and prints the answer.
5+
6+
// But it does not return the answer.
7+
8+
// Because there is no return, the function automatically gives back undefined.
9+
10+
// So when we use the function inside the second console.log, the value is undefined.
411

512
function multiply(a, b) {
613
console.log(a * b);
14+
715
}
816

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

1119
// =============> write your explanation here
20+
// console.log and return are not the same.
21+
22+
// console.log only prints the value to the console.
23+
24+
// It does not send the value back to the function call.
25+
26+
// Because there was no return statement, the function automatically returned undefined.
1227

13-
// Finally, correct the code to fix the problem
28+
// To fix the issue, I replaced console.log with return.
29+
30+
// By returning a * b, the function now sends the calculated value back to where it was called.
31+
32+
// As a result, the correct value is displayed instead of undefined.
1433
// =============> write your new code here
34+
function multiply(a, b) {
35+
return (a * b);
36+
37+
}
38+
39+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

0 commit comments

Comments
 (0)