Skip to content

Commit 1a63f23

Browse files
committed
completed the mandatory debugs
1 parent c3bbdff commit 1a63f23

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

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

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

3-
// =============> write your prediction here
3+
// =============> In line 6, the word return is missing, I assume.
44

55
function multiply(a, b) {
66
console.log(a * b);
77
}
88

99
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1010

11-
// =============> write your explanation here
11+
// =============> $`{multiply(10, 32)}` is undefined.
1212

1313
// Finally, correct the code to fix the problem
1414
// =============> write your new code here
15+
16+
function multiply(a, b) {
17+
return a * b;
18+
}
19+
20+
console.log(multiply(10, 32));

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// =============> It will give an error; line 5 and 6 should be in one line.
33

44
function sum(a, b) {
55
return;
@@ -8,6 +8,12 @@ function sum(a, b) {
88

99
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1010

11-
// =============> write your explanation here
11+
// =============> The output is undefined because return and a + b are in two different lines.
1212
// Finally, correct the code to fix the problem
1313
// =============> write your new code here
14+
15+
function sum(a, b) {
16+
return a + b;
17+
}
18+
19+
console.log(sum(10, 32));

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

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

33
// Predict the output of the following code:
4-
// =============> Write your prediction here
4+
// =============> It will probaby return the last digit as a string.
55

66
const num = 103;
77

@@ -14,11 +14,21 @@ console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1414
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1515

1616
// Now run the code and compare the output to your prediction
17-
// =============> write the output here
17+
// =============> Aha, I was wrong. The outputs for all the console.log is 3
1818
// Explain why the output is the way it is
19-
// =============> write your explanation here
19+
// =============> because, the function takes 'const num = 103' as input.
2020
// Finally, correct the code to fix the problem
2121
// =============> write your new code here
2222

23+
function getLastDigit(num) {
24+
return num.toString().slice(-1);
25+
}
26+
2327
// This program should tell the user the last digit of each number.
2428
// Explain why getLastDigit is not working properly - correct the problem
29+
30+
// This code should be working better. It takes the last digit of the number as a string
31+
// and at last, change that string into a number;
32+
function getLastDigit(num) {
33+
return Number(num.toString().slice(-1));
34+
}

0 commit comments

Comments
 (0)