Skip to content

Commit 8f610f3

Browse files
Fix 2-mandatory-debug/1.js: put return value on the same line
1 parent d207836 commit 8f610f3

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// I predict it will print "The sum of 10 and 32 is undefined", because
4+
// the function returns before it reaches a + b.
35

46
function sum(a, b) {
5-
return;
6-
a + b;
7+
return a + b;
78
}
89

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

1112
// =============> write your explanation here
13+
// The return statement was on its own line with nothing after it, so the
14+
// function returned undefined straight away. JavaScript treats the line
15+
// break after return as the end of the statement, so a + b on the next
16+
// line was never reached.
1217
// Finally, correct the code to fix the problem
1318
// =============> write your new code here
19+
// I moved a + b onto the same line as return: return a + b

0 commit comments

Comments
 (0)