Skip to content

Commit 027513b

Browse files
committed
refactored code and explained why original code wasn't working
1 parent a70897f commit 027513b

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
// 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?
33

44
//function sum(a, b) {
5-
// return;
5+
// return;
66
// a + b;
77
//}
88

99
//console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1010
//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
1314

1415
function sum(a, b) {
15-
let sumResult = a + b;
16-
return sumResult;
16+
return a + b;
1717
}
1818
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

0 commit comments

Comments
 (0)