The nearest ten
- O(1) · Trivial
- Free
- Python
- JavaScript
- operations
- division
Problem
Write a function that takes a whole number, 0 or bigger, and moves it to the nearest ten: 43 stays at 40 and 47 goes up to 50.
The one that lands right in the middle goes up: 25 gives 30, not 20. And 3 is closer to 0 than to 10, so it gives 0.
Examples
43 → 40
47 → 50
100 → 100
Besides these, the challenge has hidden tests that are revealed when you submit your solution.
You start with this
Python
def round_to_ten(n):
passJavaScript
function roundToTen(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.