Skip to content

Commit c3dada4

Browse files
committed
Predict and solve 1.js in debug
1 parent 627533f commit c3dada4

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
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+
/*
49
function sum(a, b) {
510
return;
611
a + b;
712
}
813
914
console.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.

0 commit comments

Comments
 (0)