Skip to content

Commit 329939a

Browse files
committed
Update prediction and explanation for multiply function output
1 parent b4452ff commit 329939a

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

  • Sprint-3/2-mandatory-debug

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

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

33
// =============> write your prediction here
4-
// My prediction is the output will be "The result of multiplying 10 and 32 is undefined"
4+
// My prediction is '320' would be printed first followed by "The result of multiplying 10 and 32 is undefined"
55
// This occurs because 'multiply()' does not return anything
66

77
function multiply(a, b) {
@@ -11,6 +11,11 @@ function multiply(a, b) {
1111
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1212

1313
// =============> write your explanation here
14+
// The template literal calls 'multiply(10, 32) to build the string
15+
// Inside multiply, 'console.log(a * b)' runs immediately, printing '320'
16+
// This happens before the outer 'console.log' line finishes, because JavaScript has to evaluate 'multiply(10, 32)' first to know what to put in the template
17+
// 'multiply's' function body only contains a 'console.log' statement without a 'return' keyword
18+
// A function with no explicit return statement returns 'undefined' by default.
1419

1520
// Finally, correct the code to fix the problem
1621
// =============> write your new code here

0 commit comments

Comments
 (0)