Skip to content

Commit 627533f

Browse files
committed
Predict and solve 0.js in debug
1 parent cf6d301 commit 627533f

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

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

33
// =============> write your prediction here
4+
// Answer: I predict the console will log first 320, and then on a new line "The result of multiplying 10 and 32 is ${NaN}"
5+
// This is because the function logs the result in it's body, so it will log it first as it is run, but
6+
// because it's not explicitly returning anything, it will just return NaN into the string literal logged at the end.
47

8+
/*
59
function multiply(a, b) {
610
console.log(a * b);
711
}
812
913
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
14+
*/
1015

1116
// =============> write your explanation here
17+
// Answer: In reality, I was almost correct, but the function returned undefined, not NaN, so it logged
18+
// 320, and then The result of multiplying 10 and 32 is undefined. Oh and also of course the string
19+
// interpolation brackets weren't included in the logged string like I had predicted.
20+
// I will fix the problem by returning a * b in the function body, instead of logging it.
1221

1322
// Finally, correct the code to fix the problem
1423
// =============> write your new code here
24+
25+
function multiply(a, b) {
26+
return a * b;
27+
}
28+
29+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

0 commit comments

Comments
 (0)