Skip to content

Commit 1dca903

Browse files
committed
Fix sum function to return the correct sum
1 parent 588db92 commit 1dca903

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// I predict that the output of the console.log statement will be "The sum of 10 and 32
4+
// is undefined" because the sum function does not return a value, it only has a return
5+
// statement without any value.
36

47
function sum(a, b) {
58
return;
@@ -9,5 +12,16 @@ function sum(a, b) {
912
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1013

1114
// =============> write your explanation here
15+
16+
// The sum function takes two parameters, a and b, and has a return statement without
17+
// any value. This means that when the function is called, it will return undefined.
18+
// Therefore, when the function is called inside the template literal, it returns
19+
// undefined, which is why the output of the console.log statement includes "undefined".
20+
1221
// Finally, correct the code to fix the problem
1322
// =============> write your new code here
23+
function sum(a, b) {
24+
return a + b;
25+
}
26+
27+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

0 commit comments

Comments
 (0)