Skip to content

Commit cc17fe8

Browse files
committed
Fix sum function return
1 parent 3c54085 commit cc17fe8

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
// Predict and explain first...
2+
3+
// Prediction: I predict that the function will return undefined
4+
// because return stops the function before a + b can be calculated.
5+
26
// =============> write your prediction here
37

48
function sum(a, b) {
5-
return;
6-
a + b;
9+
return a + b;
710
}
811

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

14+
// Explanation: The original code used return on its own line.
15+
// When JavaScript reaches return, the function stops and returns
16+
// undefined. The line a + b is therefore never used.
17+
// We need to return a + b together.
18+
1119
// =============> write your explanation here
1220
// Finally, correct the code to fix the problem
13-
// =============> write your new code here
21+
// =============> write your new code here

0 commit comments

Comments
 (0)