Skip to content

Commit 767c156

Browse files
solution exercise 3 mandatory debug
1 parent a118f95 commit 767c156

File tree

1 file changed

+16
-5
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+16
-5
lines changed

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

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

33
// Predict the output of the following code:
4-
// =============> Write your prediction here
5-
4+
// =============> the slice index can't be negative
65
const num = 103;
76

87
function getLastDigit() {
@@ -14,11 +13,23 @@ console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1413
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1514

1615
// Now run the code and compare the output to your prediction
17-
// =============> write the output here
16+
// =============>
17+
// The last digit of 42 is 3
18+
//The last digit of 105 is 3
19+
//The last digit of 806 is 3
1820
// Explain why the output is the way it is
19-
// =============> write your explanation here
21+
// =============> the constant was declared out of the function
2022
// Finally, correct the code to fix the problem
21-
// =============> write your new code here
23+
// =============>
24+
25+
26+
function getLastDigit(num) {
27+
return num.toString().slice(-1);
28+
}
29+
30+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
31+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
32+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
2233

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

0 commit comments

Comments
 (0)