Skip to content

Commit 7229e50

Browse files
committed
1.js
1 parent db6578c commit 7229e50

File tree

1 file changed

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

1 file changed

+14
-6
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// function sum(a, b) {
4+
// return;
5+
// a + b;
6+
// }
37

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)}`);
8+
// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
9+
// The output will be: The sum of 10 and 32 is undefined
10+
// This is because the function returns immediately with no value, so a + b is never executed.
1011

1112
// =============> write your explanation here
13+
// The return statement ends the function before a + b is calculated, so the function returns undefined.
14+
1215
// Finally, correct the code to fix the problem
1316
// =============> write your new code here
17+
function sum(a, b) {
18+
return a + b;
19+
}
20+
21+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

0 commit comments

Comments
 (0)