Morse Code Translator

Translate a string into morse code.

Easy1/7/2024

Problem statement

Your task is to write a program that takes a string as input and translates it into its equivalent in international Morse code. The input will be a string of lowercase space-separated words where each word consists of nothing but the letters a-z. Add spaces between the words but not between the letters of a word in morse code. Here is the alphabet in morse code:

a: .-      g: --.     m: --      s: ...     y: -.--  
b: -...    h: ....    n: -.      t: -       z: --..  
c: -.-.    i: ..      o: ---     u: ..-     
d: -..     j: .---    p: .--.    v: ...-    
e: .       k: -.-     q: --.-    w: .--     
f: ..-.    l: .-..    r: .-.     x: -..-    

For example, the string

lorem ipsum

should be translated to

.-..---.-..-- ...--......---

Problem leaderboard

#
Size
%
Users
#1
101 c.
Top 4%
Shanethegamer
#2
102 c.
Top 8%
tree
#3
113 c.
Top 12%
AlephSquirrel
#4
116 c.
Top 16%
helbling
#5
123 c.
Top 20%
Lv0Sys
#6
124 c.
Top 24%
sean
#7
133 c.
Top 28%
Natanaelel
#8
136 c.
Top 32%
cers
#9
139 c.
Top 36%
val
#10
140 c.
Top 40%
voytxt
#11
145 c.
Top 44%
Thomasdcrt
#12
150 c.
Top 48%
scpchicken
#13
162 c.
Top 56%
SephQ
Alex
#14
166 c.
Top 60%
Rag
#15
170 c.
Top 64%
davyboyh
#16
172 c.
Top 68%
maximec-indy
#17
174 c.
Top 72%
Pascal
#18
186 c.
Top 76%
Mif712
#19
195 c.
Top 80%
ComputerKWasTaken
#20
200 c.
Top 84%
thaispalmer
#21
219 c.
Top 88%
KrausRaus
#22
258 c.
Top 92%
madeforlosers
#23
593 c.
Top 96%
jules
#24
606 c.
Top 100%
Arnaud