Skip to content

Commit 7a75478

Browse files
committed
error fixed and questions answered
1 parent f775ea1 commit 7a75478

File tree

1 file changed

+14
-0
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+14
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// An error will occur because the function 'sum' has a return statement that is not returning any value.
34

5+
/*
46
function sum(a, b) {
57
return;
68
a + b;
79
}
810
911
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
12+
*/
1013

1114
// =============> write your explanation here
15+
/* The error occurs because the 'sum' function has a return statement that does not return any value. In JavaScript,
16+
when a function reaches a return statement without a value, it returns 'undefined' by default. Therefore, when we
17+
call 'sum(10, 32)', it returns 'undefined', and the output will be "The sum of 10 and 32 is undefined". To fix this,
18+
we need to ensure that the function returns the result of 'a + b'.*/
19+
1220
// Finally, correct the code to fix the problem
1321
// =============> write your new code here
22+
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)