Skip to content

Commit 3f7a1aa

Browse files
committed
Fix explanation comments in sum function and restore correct implementation
1 parent 5740fd5 commit 3f7a1aa

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
// =============> write your explanation here
1818
// it wasn't completely as I predicted, the first console log statement inside the function multiply did worked and
19-
// it printed 320, which measn that the function parameters a and b took the values 10 and 32 from the function call multiply(10, 32).
19+
// it printed 320, which means that the function parameters a and b took the values 10 and 32 from the function call multiply(10, 32).
2020
// but the second console log statement printed "The result of multiplying 10 and 32 is undefined" because the function multiply does not return any value,
2121
// so the result of multiplying 10 and 32 is undefined.
2222

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// in this code we have a function called sum that takes two parameters a and b,
4+
// inside the function there is a return statement followed by a; and then an expression a + b;
5+
// but in JavaScript, when a return statement is executed, the function exits immediately and any code after the return statement is not executed.
6+
// so the function will always return undefined because there is no value after the return statement.
7+
// so the final output will be "The sum of 10 and 32 is undefined"
38

4-
function sum(a, b) {
5-
return;
6-
a + b;
7-
}
9+
// function sum(a, b) {
10+
// return;
11+
// a + b;
12+
// }
813

9-
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
14+
// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1015

1116
// =============> write your explanation here
17+
18+
// it behaved exactly as I predicted, the console log statement printed "The sum of 10 and 32 is undefined"
1219
// Finally, correct the code to fix the problem
1320
// =============> write your new code here
21+
// to correct the code we just need to remove the semicolon after the return statement.
22+
23+
function sum(a, b) {
24+
return a + b;
25+
}
26+
27+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

0 commit comments

Comments
 (0)