Skip to content

Commit 494b2e5

Browse files
committed
mandatory debug part is solved.
1 parent 5666561 commit 494b2e5

File tree

3 files changed

+37
-16
lines changed

3 files changed

+37
-16
lines changed

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

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

3-
// =============> write your prediction here
3+
// =============> My prediction is code wont return anything because the function does not have a return statement.
44

5-
function multiply(a, b) {
5+
/* function multiply(a, b) {
66
console.log(a * b);
77
}
88
9-
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
10-
11-
// =============> write your explanation here
9+
console.log(`The result of multiplying 10 and 32 is `${multiply(10, 32)}`);
10+
*/
11+
// =============> Once return statement is added, it will return the result of the multiplication.
1212

1313
// Finally, correct the code to fix the problem
14-
// =============> write your new code here
14+
// =============>
15+
16+
function multiply(a,b)
17+
{
18+
return a*b;
19+
}
20+
21+
console.log(`result of multiplying 2 times 2 = ${multiply(2, 2)}`);

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// =============> Problem here is that sum does not return no value because return statement and a + b is in different lines.
33

4-
function sum(a, b) {
4+
/*function sum(a, b) {
55
return;
66
a + b;
77
}
88
99
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
10-
11-
// =============> write your explanation here
10+
*/
11+
// =============> Once we put a + b back in return statement it will work with no problem.
1212
// Finally, correct the code to fix the problem
1313
// =============> write your new code here
14+
15+
function sum(a, b)
16+
{
17+
return a + b;
18+
}
19+
20+
console.log(`The sum of 45 and 12 is ${sum(45, 12)}`); // Output: "The sum of 10 and 32 is 42"

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

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

33
// Predict the output of the following code:
4-
// =============> Write your prediction here
4+
// =============> output would be undefined because getLastDigit uses global variable num.
55

6-
const num = 103;
6+
/* const num = 103;
77
88
function getLastDigit() {
99
return num.toString().slice(-1);
@@ -12,13 +12,20 @@ function getLastDigit() {
1212
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
1313
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1414
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
15-
15+
*/
1616
// Now run the code and compare the output to your prediction
17-
// =============> write the output here
17+
// =============> Program is returning 3 for all console.log's.
1818
// Explain why the output is the way it is
19-
// =============> write your explanation here
19+
// =============> Num is defined to 103 which is global so anytime program calls getLastDigit it returns 3.
2020
// Finally, correct the code to fix the problem
21-
// =============> write your new code here
21+
// =============>
22+
23+
function getLastDigit(num)
24+
{
25+
return num.toString().slice(-1);
26+
}
27+
28+
console.log(`The last digit of 41 is ${getLastDigit(41)}`);
2229

2330
// This program should tell the user the last digit of each number.
2431
// Explain why getLastDigit is not working properly - correct the problem

0 commit comments

Comments
 (0)