Skip to content

Commit aaa500c

Browse files
committed
Add predictions and explanations for multiply and sum functions, and correct their implementations
1 parent 0642903 commit aaa500c

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

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

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

33
// =============> write your prediction here
4+
// 320
45

56
function multiply(a, b) {
67
console.log(a * b);
@@ -10,5 +11,14 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1011

1112
// =============> write your explanation here
1213

14+
/*Explanation: The `multiply` function calculates `a * b` and immediately prints it to
15+
the console, but it doesn't use the `return` keyword to hand the value back.
16+
1317
// Finally, correct the code to fix the problem
1418
// =============> write your new code here
19+
20+
function multiply(a, b) {
21+
return a * b;
22+
}
23+
24+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Predict and explain first...
22
// =============> write your prediction here
33

4+
//The sum would return as undefined.
5+
46
function sum(a, b) {
57
return;
68
a + b;
@@ -9,5 +11,15 @@ function sum(a, b) {
911
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1012

1113
// =============> write your explanation here
14+
15+
// Explanation: The return keyword is used and the functions is not executed because the expression is on a different line
16+
which means the computer would not run the expression alongside the return keyword.
17+
1218
// Finally, correct the code to fix the problem
1319
// =============> write your new code here
20+
21+
function sum(a, b) {
22+
return a + b;
23+
}
24+
25+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

0 commit comments

Comments
 (0)