Skip to the content

The middle letter

Problem

Write a function that takes a word (with at least one letter) and returns its middle letter: with "sun" you return "u".

If the word has an even number of letters there are two in the middle: return the left one, so with "moon" you return "o".

Examples

  • "sun" → "u"

  • Even length

    "moon" → "o"

  • "chocolate" → "o"

  • "computer" → "p"

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

You start with this

Python

def middle_letter(text):
    pass

JavaScript

function middleLetter(text) {
}
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 →