Skip to content

Commit 0e0827d

Browse files
committed
Explained and fixed the bug proper use of return statment
1 parent 1250064 commit 0e0827d

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// I predict that the code will run but it will print undefined because the return expression is not setup properly
33

4-
function sum(a, b) {
4+
/*function sum(a, b) {
55
return;
66
a + b;
77
}
88
9-
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
9+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);*/
10+
11+
// When we run the code it printed out undefined because the return keyword is there but the expression that needs to be returned is not on the same line
12+
// therefore the return keyword can't reach the expression and the expression is ignored because the function has done execution right after it reaches the return keyword
1013

11-
// =============> write your explanation here
1214
// Finally, correct the code to fix the problem
13-
// =============> write your new code here
15+
// Here is the fixed code
16+
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)