Skip to content

Commit 059a731

Browse files
committed
move a + b onto the same line as return
1 parent 5fba492 commit 059a731

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

  • Sprint-2/2-mandatory-debug

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// The output will be "The sum of 10 and 32 is undefined" because the
4+
// function sum does not return the result of a + b. The return
5+
// statement is empty, so it returns undefined by default.
36

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

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

1114
// =============> write your explanation here
15+
// In JS, when a function has a return statement without a value,
16+
// it returns undefined. The expression a+b on the next line is
17+
// never reached. Fix -> put a+b on the same line as return,
18+
// or remove the return statement and just have a+b as the last line
19+
// of the function.
20+
1221
// Finally, correct the code to fix the problem
1322
// =============> write your new code here
23+
function sum(a, b) {
24+
return a + b;
25+
}
26+
27+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

0 commit comments

Comments
 (0)