Skip to content

Commit 1250064

Browse files
committed
Explaning and fixing the bug by adding return keyword
1 parent 47e6f25 commit 1250064

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

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

3-
// =============> write your prediction here
3+
// I predict the code will run normally and print the result of a * b on the first console, but it will return undefined on the
4+
// second console.log
45

5-
function multiply(a, b) {
6+
/*function multiply(a, b) {
67
console.log(a * b);
78
}
89
9-
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
10+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);*/
1011

11-
// =============> write your explanation here
12+
// The reason for printing undefined is that we didn't define a return value so the js doesn't know what to return and it simply returns undefined
13+
// We can fix the code by replacing the console.log with a return keyword so the js knows what to return when the function is called
1214

1315
// Finally, correct the code to fix the problem
14-
// =============> write your new code here
16+
// Here is the fixed code
17+
18+
function multiply(a, b) {
19+
return a * b;
20+
}
21+
22+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

0 commit comments

Comments
 (0)