Skip to content

Commit 9e3b8c1

Browse files
fix getLastDigit to return last digit of any input number
1 parent 82ad98f commit 9e3b8c1

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

  • Sprint-2/2-mandatory-debug

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5+
// I predicted that it will show undefined or fixed number like 3
56

67
const num = 103;
78

@@ -15,10 +16,24 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1516

1617
// Now run the code and compare the output to your prediction
1718
// =============> write the output here
19+
// The last digit of 42 is 3
20+
// The last digit of 105 is 3
21+
// The last digit of 806 is 3
1822
// Explain why the output is the way it is
23+
// num has fix number which is 3 and i return this fix number
1924
// =============> write your explanation here
25+
// user want last digit whatever number they put but i set up a fix number which will return that one that's why now i removed fixed number and wrote a parameter in function
26+
// which will contain user number whatever number they put and get the last digit.
2027
// Finally, correct the code to fix the problem
2128
// =============> write your new code here
2229

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)}`);
37+
2338
// This program should tell the user the last digit of each number.
2439
// Explain why getLastDigit is not working properly - correct the problem

0 commit comments

Comments
 (0)