Skip to content

Commit 5d7a4cf

Browse files
authored
Correct sum function to return a + b
Fixed the sum function to return the correct sum of two numbers.
1 parent 7b557c2 commit 5d7a4cf

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// Output: The sum of 10 and 32 is undefined
34

45
function sum(a, b) {
56
return;
@@ -9,5 +10,12 @@ function sum(a, b) {
910
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1011

1112
// =============> write your explanation here
13+
// Because there is no value after `return`, the function returns undefined.
14+
// The line a + b is unreachable code, meaning it will never run.
1215
// Finally, correct the code to fix the problem
1316
// =============> write your new code here
17+
function sum(a, b) {
18+
return a + b;
19+
}
20+
21+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

0 commit comments

Comments
 (0)