File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
Sprint-2/2-mandatory-debug Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
22// =============> write your prediction here
3+ // Prediction: The code should output - "The sum of 10 and 32 is 42"
4+ // But the code will return undefined instead of 42.
35
6+ /* Original code
47function sum(a, b) {
58 return;
69 a + b;
710}
811
912console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
13+ */
14+
15+ // =============> Error message
16+ // The sum of 10 and 32 is undefined
1017
1118// =============> write your explanation here
19+ // MDN Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return
20+
21+ // The function uses `return;` without an expression.
22+ // According to MDN, if a return statement has no value, the function returns undefined.
23+ // So when `sum(10, 32)` is called, it returns undefined.
24+ // To fix this, the return statement must include the expression `a + b`.
25+
1226// Finally, correct the code to fix the problem
1327// =============> write your new code here
28+ function sum ( a , b ) {
29+ return a + b ;
30+ }
31+
32+ console . log ( `The sum of 10 and 32 is ${ sum ( 10 , 32 ) } ` ) ;
You can’t perform that action at this time.
0 commit comments