Skip to content

Commit ebffeae

Browse files
committed
Predict and explaind bug. Fix by changing function to return a * b
1 parent 9ff0a0b commit ebffeae

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

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

33
// =============> write your prediction here
4+
//The multiply function doesn't return anything, only prints to console so the function call will have value undefined.
5+
//So when line 12 is executed, first it will print "The result of multiplying 10 and 32 is undefined"
6+
//Then on a new line it prints 320
47

5-
function multiply(a, b) {
6-
console.log(a * b);
7-
}
8+
//function multiply(a, b) {
9+
// console.log(a * b);
10+
//}
811

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

1114
// =============> write your explanation here
12-
15+
//It first printed 320, then printed "The result of multiplying 10 and 32 is undefined" on the next line
16+
//I think this is because it goes through the line 12, executes the multiply function call first, then finishes the
17+
//console.log function call.
1318
// Finally, correct the code to fix the problem
1419
// =============> write your new code here
20+
21+
function multiply(a, b) {
22+
return a * b;
23+
}
24+
25+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

0 commit comments

Comments
 (0)