Skip to content

Commit 5740fd5

Browse files
committed
Fix multiply function to return the product of two parameters
1 parent 3dcaa8f commit 5740fd5

File tree

1 file changed

+21
-4
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+21
-4
lines changed

Sprint-2/2-mandatory-debug/0.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
// Predict and explain first...
22

33
// =============> write your prediction here
4+
// in this code we have a function called multiply that takes two parameters a and b,
5+
//inside the function it will print the result of multiplying a and b,
6+
// but a and b are not defined, not in global scope nor local scope, so we will get error.
7+
// there is another console log statement that will print a string with the result of multiplying 10 and 32,
8+
// but the function multiply does not return any value, so the result will be undefined.
9+
// so the final output will be "The result of multiplying 10 and 32 is undefined"
410

5-
function multiply(a, b) {
6-
console.log(a * b);
7-
}
11+
// function multiply(a, b) {
12+
// console.log(a * b);
13+
// }
814

9-
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
15+
// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1016

1117
// =============> write your explanation here
18+
// it wasn't completely as I predicted, the first console log statement inside the function multiply did worked and
19+
// it printed 320, which measn that the function parameters a and b took the values 10 and 32 from the function call multiply(10, 32).
20+
// but the second console log statement printed "The result of multiplying 10 and 32 is undefined" because the function multiply does not return any value,
21+
// so the result of multiplying 10 and 32 is undefined.
1222

1323
// Finally, correct the code to fix the problem
1424
// =============> write your new code here
25+
// I will add a return statement to the function multiply that returns the result of multiplying a and b.
26+
27+
function multiply(a, b) {
28+
return (a * b);
29+
}
30+
31+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

0 commit comments

Comments
 (0)