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-3/2-mandatory-debug/1.js
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -2,17 +2,17 @@
2
2
// The function will not return the expected result because whilst sum takes in two arguments it cannot add a+b together because it hasn't been stored in a variable before return so when we call sum it will be undefined?
3
3
4
4
//function sum(a, b) {
5
-
// return;
5
+
// return;
6
6
// a + b;
7
7
//}
8
8
9
9
//console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
10
10
//console output: The sum of 10 and 32 is undefined
11
-
// sum is undefined because we haven't stored the operation we want it to perform correctly in a variable so its value is undefined.
12
-
// Finally, correct the code to fix the problem
11
+
// The return statement was placed before the calculation the code on line 6 doesn't get executed as return ends the function on line 5. The function would need to return a+b in order for it to return the result.
12
+
13
+
//Finally, correct the code to fix the problem
13
14
14
15
functionsum(a,b){
15
-
letsumResult=a+b;
16
-
returnsumResult;
16
+
returna+b;
17
17
}
18
18
console.log(`The sum of 10 and 32 is ${sum(10,32)}`);
0 commit comments