Skip to content

Commit 5fba492

Browse files
committed
change console.log to return in multiply function
1 parent e90b646 commit 5fba492

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

  • Sprint-2/2-mandatory-debug

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

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

33
// =============> write your prediction here
4+
// The code will print "The result of multiplying 10 and 32 is undefined"
5+
// for the result because the function multiply does not return any
6+
// value, it only uses console.log to print the result of the
7+
// multiplication instead of return. Therefore when we try to use
8+
// the result of the function in the template literal, it will be
9+
// undefined as it logs the value but returns nothing.
410

5-
function multiply(a, b) {
6-
console.log(a * b);
7-
}
11+
// function multiply(a, b) {
12+
// console.log(a * b);
13+
// }
814

9-
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
15+
// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1016

1117
// =============> write your explanation here
18+
// console.log() inside a function will print the result to the console
19+
// but it does not return any value. When we try to use the result
20+
// of the function in a template literal, it will be undefined
21+
// because the function does not return anything. To use a function's
22+
// results inside a template literal, the function must return
23+
// a value instead of just logging it to the console.
1224

1325
// Finally, correct the code to fix the problem
1426
// =============> write your new code here
27+
function multiply(a, b) {
28+
return a * b;
29+
}
30+
31+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

0 commit comments

Comments
 (0)