Skip to content

Commit 8caddb1

Browse files
committed
Complete debug exercise 1 - sum return expression
1 parent 65cb89c commit 8caddb1

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// Prediction: return; exits immediately with undefined, so a + b never runs
4+
// and the message shows "undefined".
35

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

9-
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
11+
//console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1012

1113
// =============> write your explanation here
14+
// Explanation: A bare return; returns undefined. The expression must be on
15+
// the same return statement: return a + b;
16+
1217
// Finally, correct the code to fix the problem
1318
// =============> write your new code here
19+
function sum(a, b) {
20+
return a + b;
21+
}
22+
23+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
24+

0 commit comments

Comments
 (0)