File tree Expand file tree Collapse file tree
Sprint-2/2-mandatory-debug Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11// Predict and explain first...
22// =============> write your prediction here
3+ // The output will be "The sum of 10 and 32 is undefined" because the
4+ // function sum does not return the result of a + b. The return
5+ // statement is empty, so it returns undefined by default.
36
4- function sum ( a , b ) {
5- return ;
6- a + b ;
7- }
7+ // function sum(a, b) {
8+ // return;
9+ // a + b;
10+ // }
811
9- console . log ( `The sum of 10 and 32 is ${ sum ( 10 , 32 ) } ` ) ;
12+ // console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1013
1114// =============> write your explanation here
15+ // In JS, when a function has a return statement without a value,
16+ // it returns undefined. The expression a+b on the next line is
17+ // never reached. Fix -> put a+b on the same line as return,
18+ // or remove the return statement and just have a+b as the last line
19+ // of the function.
20+
1221// Finally, correct the code to fix the problem
1322// =============> write your new code here
23+ function sum ( a , b ) {
24+ return a + b ;
25+ }
26+
27+ console . log ( `The sum of 10 and 32 is ${ sum ( 10 , 32 ) } ` ) ;
You can’t perform that action at this time.
0 commit comments