Skip to content

Commit 94be645

Browse files
committed
completed mandatory debug
1 parent 21ace6b commit 94be645

3 files changed

Lines changed: 55 additions & 16 deletions

File tree

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

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

33
// =============> write your prediction here
4+
// I think there is nor function call has been made. a and b only inserted as function parameters.
45

5-
function multiply(a, b) {
6-
console.log(a * b);
7-
}
6+
// function multiply(a, b) {
7+
// console.log(a * b);
8+
// }
89

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

1112
// =============> write your explanation here
13+
// The result of multiplying 10 and 32 is undefined. This is the error. Now I think the reason for showing the result undefined is that
14+
// console.log(a * b); only prints 320 but the function does not return anything.
1215

1316
// Finally, correct the code to fix the problem
1417
// =============> write your new code here
18+
// The correct code:
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: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// I think only return; doesnot mean anything means it won't return anything. Besides, the expression a + b; won't also work
4+
// cause after calculating a + b it won't return anything and the output will show undefined value.
35

4-
function sum(a, b) {
5-
return;
6-
a + b;
7-
}
6+
// function sum(a, b) {
7+
// return;
8+
// a + b;
9+
// }
810

9-
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
11+
// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1012

1113
// =============> write your explanation here
14+
// My prediction exactly matches with the output after I run code.
1215
// Finally, correct the code to fix the problem
1316
// =============> write your new code here
17+
// The correct code:
18+
19+
function sum(a, b) {
20+
return (a + b);
21+
}
22+
23+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,42 @@
22

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5+
// i think the function won't return anything for numbers 42, 105 and 806 because the variable num contains value 103 and the return will only
6+
// work with 103 inside the function. There is no relation between const num = 103; and 42, 105 and 806.
57

6-
const num = 103;
8+
// const num = 103;
79

8-
function getLastDigit() {
9-
return num.toString().slice(-1);
10-
}
10+
// function getLastDigit() {
11+
// return num.toString().slice(-1);
12+
// }
1113

12-
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
13-
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
14-
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
14+
// console.log(`The last digit of 42 is ${getLastDigit(42)}`);
15+
// console.log(`The last digit of 105 is ${getLastDigit(105)}`);
16+
// console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1517

1618
// Now run the code and compare the output to your prediction
1719
// =============> write the output here
20+
// The output:
21+
// The last digit of 42 is 3
22+
// The last digit of 105 is 3
23+
// The last digit of 806 is 3
24+
1825
// Explain why the output is the way it is
1926
// =============> write your explanation here
27+
// The output is quite similar to my prediction. When the function tried to find out function calls for getLastDigit(42), getLastDigit(105)
28+
// and getLastDigit(806) it doesn't find any of these because those didn't match with the variable declaration. As the function wokred only
29+
// with 103, it returned value for 103 and printed 3 as last digit for all three values.
2030
// Finally, correct the code to fix the problem
2131
// =============> write your new code here
32+
// The correct code:
33+
34+
function getLastDigit(num) {
35+
return num.toString().slice(-1);
36+
}
37+
38+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
39+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
40+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
2241

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

0 commit comments

Comments
 (0)