Skip to content

Commit 33d07a2

Browse files
committed
added log explanation and fixed code
1 parent 4d3da6f commit 33d07a2

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
// Predict and explain first...
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

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)}`);
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
13+
414
function sum(a, b) {
5-
return;
6-
a + b;
15+
let sumResult = a + b;
16+
return sumResult;
717
}
8-
918
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
10-
11-
// =============> write your explanation here
12-
// Finally, correct the code to fix the problem
13-
// =============> write your new code here

0 commit comments

Comments
 (0)