The last digit
- O(1) · Trivial
- Free
- Python
- JavaScript
- operations
- digits
Problem
Write a function that takes a whole number and returns its last digit, the one on the right. With 407 you return 7, with 30 you return 0.
The sign doesn't count: the last digit of -47 is 7. Not -7, not 3.
Examples
407 → 7
30 → 0
8 → 8
Besides these, the challenge has hidden tests that are revealed when you submit your solution.
You start with this
Python
def last_digit(n):
passJavaScript
function lastDigit(n) {
}Solve this challenge
It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.
More O(1) challenges
- The last fourPython · JavaScript · strings · indexes
- The letter gradePython · JavaScript · conditionals · strings · comparisons
- The letters left overPython · JavaScript · strings · operations
- The middle letterPython · JavaScript · strings · indexes
- The name, written rightPython · JavaScript · strings
- The nearest tenPython · JavaScript · operations · division