Skip to content

Commit d1a35bc

Browse files
committed
Fix sum function return statement
1 parent 1d044cb commit d1a35bc

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// =============> write your prediction here:This is the error:The sum of 10 and 32 is undefined.
3+
// The code will run without a syntax error, but it will return undefined instead of 42.
34

45
function sum(a, b) {
56
return;
@@ -8,6 +9,15 @@ function sum(a, b) {
89

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

11-
// =============> write your explanation here
12+
// =============> write your explanation here:
13+
//The problem is that return; immediately ends the function://return;
14+
//a + b;
15+
16+
//if we write anything after return(next line)is unreachable, so a + b doesn't run. The function therefore returns undefined.
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)}`);

0 commit comments

Comments
 (0)