Skip to content

Commit 59aa251

Browse files
committed
Fixed sum() function
1 parent d460d91 commit 59aa251

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

  • Sprint-2/2-mandatory-debug

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
//I think this code will not give correct output, it will give undefined.
34

4-
function sum(a, b) {
5+
/*function sum(a, b) {
56
return;
67
a + b;
78
}
89
9-
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
10+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);*/
1011

1112
// =============> write your explanation here
13+
/*This code will print undefined because return; stops the function immediately.
14+
The line a + b is never executed, so the function returns undefined and the template
15+
string receives undefined instead of the sum.*/
16+
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+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

0 commit comments

Comments
 (0)