The middle letter
- O(1) · Trivial
- Free
- Python
- JavaScript
- strings
- indexes
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):
passJavaScript
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.