Skip to content

Commit 94da557

Browse files
author
Pretty Taruvinga
committed
predicted the error and corrected the code
1 parent f1cd001 commit 94da557

File tree

1 file changed

+5
-1
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
// Predict and explain first...
22

33
// =============> write your prediction here
4-
4+
// I predict that the error will occur because the function 'multiply' does not return any value, so when we try to use it inside the template literal, it will return 'undefined'.
5+
// This will result in the output being "The result of multiplying 10 and 32 is undefined" instead of the expected product of 10 and 32.
56
function multiply(a, b) {
67
console.log(a * b);
78
}
89

910
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1011

1112
// =============> write your explanation here
13+
// The error occurs because the function 'multiply' does not have a return statement, so it returns 'undefined' by default. When we try to use the result of 'multiply(10, 32)' inside the template literal, it evaluates to 'undefined', which is not the expected output. To fix this error, we need to add a return statement in the 'multiply' function to return the product of 'a' and 'b'.
1214

1315
// Finally, correct the code to fix the problem
1416
// =============> write your new code here
17+
function multiply(a, b) {
18+
return a * b;

0 commit comments

Comments
 (0)