Skip to content

Commit 818cc32

Browse files
committed
Predict and explain bug. Fix by moving a + b before ; in return line so properly returned
1 parent ebffeae commit 818cc32

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
//when the return line is executed, the function exits. a + b is a separate line because it
4+
//is after the semicolon, so a + b is never reached and not returned. So line 11 will print
5+
//The The sum of 10 and 32 is undefined
36

4-
function sum(a, b) {
5-
return;
6-
a + b;
7-
}
7+
//function sum(a, b) {
8+
// return;
9+
// a + b;
10+
//}
811

912
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1013

1114
// =============> write your explanation here
15+
//It did as predicted, for the reason I expected
1216
// Finally, correct the code to fix the problem
1317
// =============> write your new code here
18+
19+
function sum(a, b) {
20+
return a + b;
21+
}
22+
23+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

0 commit comments

Comments
 (0)