Skip to content

Commit e72b13a

Browse files
fix: correct getLastDigit function to accept parameters and return the last digit of input numbers
1 parent c1c09a6 commit e72b13a

File tree

1 file changed

+9
-2
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Predict the output of the following code:
44
// =============> Write your prediction here
55
// I expect each of the calls to return the last digit of "num" which is "3" its defined as a constant and we are using that const in the return statement.
6-
6+
/*
77
const num = 103;
88
99
function getLastDigit() {
@@ -13,7 +13,7 @@ function getLastDigit() {
1313
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
1414
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1515
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
16-
16+
*/
1717
// Now run the code and compare the output to your prediction
1818
// =============> write the output here
1919
// Output:
@@ -27,6 +27,13 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`);
2727

2828
// Finally, correct the code to fix the problem
2929
// =============> write your new code here
30+
function getLastDigit(num){
31+
return num.toString().slice(-1);
32+
}
33+
34+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
35+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
36+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
3037

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

0 commit comments

Comments
 (0)