Skip to content

Commit cf34a26

Browse files
committed
Predicted, explained and fixed code errors
1 parent 689ea33 commit cf34a26

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// I dont think the code will run at all since the return is separated from the sum that should happen
4+
// the console.log() oustide the function will say the sum is undefined.
35

4-
function sum(a, b) {
5-
return;
6-
a + b;
7-
}
6+
// function sum(a, b) {
7+
// return;
8+
// a + b;
9+
// }
810

9-
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
11+
// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1012

1113
// =============> write your explanation here
14+
// The sum of 10 and 32 is undefined
15+
// I was wrong, I thought that the code would not run.
16+
// The output says the sum is undefined because the return statement and the "a + b" are separated by ;
17+
// To fix it, I just need to remove the ; next to return on line 7.
1218
// Finally, correct the code to fix the problem
1319
// =============> write your new code here
20+
function sum(a, b) {
21+
return a + b;
22+
}
23+
24+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

0 commit comments

Comments
 (0)