Skip to the content

The twelve-hour clock

Problem

Your phone shows the hour from 0 to 23, but that's not how you say it. Write a function that takes that hour and returns the everyday text: 13 gives "1 pm", 8 gives "8 am" and 23 gives "11 pm".

Watch the two that trip everyone up: 0 is "12 am" (midnight) and 12 is "12 pm" (noon).

Examples

  • 13 → "1 pm"

  • 8 → "8 am"

  • 23 → "11 pm"

Besides these, the challenge has hidden tests that are revealed when you submit your solution.

You start with this

Python

def twelve_hour(hour):
    pass

JavaScript

function twelveHour(hour) {
}
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

See all challenges →