Skip to content

Commit 79b52ed

Browse files
committed
Commit 0.js and 1.js files
1 parent 607ca58 commit 79b52ed

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,35 @@
11
// Predict and explain first...
2+
// The console will print:
3+
// 320
4+
// The result of multiplying 10 and 32 is undefined
25

36
// =============> write your prediction here
7+
// The first `console.log` inside the function prints the multiplication result (320).
8+
// However, since `multiply()` does not return anything, the outer `console.log`
9+
// receives `undefined` as the value of the function call, leading to the message
10+
// "The result of multiplying 10 and 32 is undefined".
411

12+
/**
513
function multiply(a, b) {
614
console.log(a * b);
715
}
816
917
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
18+
*/
1019

1120
// =============> write your explanation here
12-
21+
// The first `console.log` inside the function prints the multiplication result (320).
22+
// However, since `multiply()` does not return anything, the outer `console.log`
23+
// receives `undefined` as the value of the function call, leading to the message
24+
// "The result of multiplying 10 and 32 is undefined".
25+
//
26+
// To fix this, the function should `return` the result instead of just logging it.
1327
// Finally, correct the code to fix the problem
28+
1429
// =============> write your new code here
30+
function multiply(a, b) {
31+
return a * b;
32+
}
33+
34+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
35+
// Output: "The result of multiplying 10 and 32 is 320"

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// The console will print: "The sum of 10 and 32 is undefined"
4+
// This happens because the `return` statement ends the function immediately,
5+
// so the expression `a + b` after it is never executed.
6+
// As a result, the function returns `undefined`.
37

8+
/**
49
function sum(a, b) {
510
return;
611
a + b;
712
}
813
14+
915
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
16+
*/
1017

1118
// =============> write your explanation here
19+
// In JavaScript, when the interpreter encounters a `return` statement,
20+
// it stops executing the rest of the function and immediately exits.
21+
// Since there’s nothing after `return` on the same line,
22+
// the function effectively returns `undefined`.
23+
// The expression `a + b` is never reached due to JavaScript’s automatic semicolon insertion.
24+
1225
// Finally, correct the code to fix the problem
1326
// =============> write your new code here
27+
function sum(a, b) {
28+
return a + b;
29+
}
30+
31+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
32+
// Output: "The sum of 10 and 32 is 42"
33+

0 commit comments

Comments
 (0)