Skip to content

Commit 2a7e1b4

Browse files
authored
Correct getLastDigit function implementation
Fixed getLastDigit function to return the correct last digit for integers.
1 parent 9a6d44e commit 2a7e1b4

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

  • Sprint-2/2-mandatory-debug

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,30 @@ console.log(`The last digit of 42 is ${getLastDigit(42)}`);
1313
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1414
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1515

16+
// [ChunYanWong] No parameter included in the function and hence the same output
17+
1618
// Now run the code and compare the output to your prediction
1719
// =============> write the output here
20+
21+
// [ChunYanWong]
22+
//The last digit of 42 is 3
23+
//The last digit of 105 is 3
24+
//The last digit of 806 is 3
25+
1826
// Explain why the output is the way it is
1927
// =============> write your explanation here
28+
29+
// [ChunYanWong] No parameter included in the function
30+
2031
// Finally, correct the code to fix the problem
2132
// =============> write your new code here
33+
// [ChunYanWong] function getLastDigit(num) {
34+
// ...
2235

2336
// This program should tell the user the last digit of each number.
2437
// Explain why getLastDigit is not working properly - correct the problem
38+
// [ChunYanWong] for the case 12.34, it will return 4 instead of the digit 2
39+
// [ChunYanWong] function getLastDigit(num) {
40+
// return Math.abs(Math.trunc(num)) % 10;
41+
// }
42+

0 commit comments

Comments
 (0)