File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
Sprint-2/2-mandatory-debug Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
2- // =============> write your prediction here
32
3+ // =============> write your prediction here
4+ // I predict that this will print: "The sum of 10 and 32 is undefined"
5+ // because the function has a return statement with no value.
6+
7+ // Explanation:
48function sum ( a , b ) {
59 return ;
610 a + b ;
11+ // =============> write your explanation here
12+ // The `return;` statement ends the function early, so `a + b` is never reached.
13+ // In JavaScript, any code after a bare `return;` is ignored (unreachable code).
14+ // That's why the function returns `undefined`, not the actual sum.
715}
816
917console . log ( `The sum of 10 and 32 is ${ sum ( 10 , 32 ) } ` ) ;
1018
11- // =============> write your explanation here
1219// Finally, correct the code to fix the problem
1320// =============> write your new code here
21+ function sum ( a , b ) {
22+ return a + b ;
23+ }
24+
25+ console . log ( `The sum of 10 and 32 is ${ sum ( 10 , 32 ) } ` ) ;
26+ // Now the function returns the correct result: 42
27+
You can’t perform that action at this time.
0 commit comments