File tree Expand file tree Collapse file tree
Sprint-3/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+ // Answer: I predict that what happens is `The sum of 10 and 32 is undefined` gets logged to the console.
4+ // That is because even though the function sum has a return statement, it doesn't return anything. There
5+ // is a value that is meant to be returned below the return statement, but because the function already returned
6+ // it will never reach that line in execution. That is why it is greyed out.
37
8+ /*
49function sum(a, b) {
510 return;
611 a + b;
712}
813
914console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
15+ */
1016
1117// =============> write your explanation here
18+ // Answer: Running the code logged "The sum of 10 and 32 is undefined" like I thought. I will fix the problem
19+ // by moving a + b; in the function body to be on the same line as return, so it gets returned instead of undefined.
20+
1221// Finally, correct the code to fix the problem
1322// =============> write your new code here
23+
24+ function sum ( a , b ) {
25+ return a + b ;
26+ }
27+
28+ console . log ( `The sum of 10 and 32 is ${ sum ( 10 , 32 ) } ` ) ;
29+
30+ // Answer: now "The sum of 10 and 32 is 42" is logged.
You can’t perform that action at this time.
0 commit comments