You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sprint-2/2-mandatory-debug/1.js
+8Lines changed: 8 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,6 @@
1
1
// Predict and explain first...
2
2
// =============> write your prediction here
3
+
// I predict the code will give an error because the sum function does not return a value.
3
4
4
5
functionsum(a,b){
5
6
return;
@@ -9,5 +10,12 @@ function sum(a, b) {
9
10
console.log(`The sum of 10 and 32 is ${sum(10,32)}`);
10
11
11
12
// =============> write your explanation here
13
+
// The function sum(a, b) has a return statement that does not return the result of a + b.
14
+
// Instead, it returns undefined because the return statement is followed by a semicolon, which ends the statement before the addition operation is executed.
12
15
// Finally, correct the code to fix the problem
13
16
// =============> write your new code here
17
+
functionsum(a,b){
18
+
returna+b;
19
+
}
20
+
21
+
console.log(`The sum of 10 and 32 is ${sum(10,32)}`);
0 commit comments