Skip to content

Commit 4ca8651

Browse files
committed
completed tasks in 2-mandatory-debug/1.js
1 parent 7183aac commit 4ca8651

File tree

1 file changed

+12
-6
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+12
-6
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// When the code is run the console log will show undefined because the function returns before the sum is calculated
4+
// function sum(a, b) {
5+
// return;
6+
// a + b;
7+
// }
38

4-
function sum(a, b) {
5-
return;
6-
a + b;
7-
}
8-
9-
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
9+
// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1010

1111
// =============> write your explanation here
12+
// When a return statement is reached the function exits immediately. Therefore the line a + b is never executed and the function returns undefined.
1213
// Finally, correct the code to fix the problem
1314
// =============> write your new code here
15+
function sum(a, b) {
16+
return a + b;
17+
}
18+
19+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

0 commit comments

Comments
 (0)