Skip to content

Commit b52edc9

Browse files
committed
spot error
1 parent 43cff66 commit b52edc9

File tree

1 file changed

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

1 file changed

+14
-3
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// =============> it should be{return a+b;}; rather than have semicolon between return and a+b
33

44
function sum(a, b) {
55
return;
@@ -8,6 +8,17 @@ function sum(a, b) {
88

99
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1010

11-
// =============> write your explanation here
11+
// =============> The return; statement immediately exits the function and returns undefined.
12+
// The line a + b; after return; never runs — it's unreachable code.So, when we call sum(10, 32), it returns undefined.
13+
// Output we get:
14+
// python
15+
// Copy
16+
// Edit
17+
// The sum of 10 and 32 is undefined
1218
// Finally, correct the code to fix the problem
13-
// =============> write your new code here
19+
// =============> my new code:
20+
function sum (a,b) {return a+b;};
21+
22+
console.log (`The sum of 10 and 32 is ${sum(10, 32)}`);
23+
24+
// the output: The sum of 10 and 32 is 42

0 commit comments

Comments
 (0)