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
99 c.
Top 3%
Lv0Sys
#2
101 c.
Top 7%
Shanethegamer
#3
102 c.
Top 10%
tree
#4
113 c.
Top 14%
AlephSquirrel
#5
116 c.
Top 17%
helbling
#6
124 c.
Top 21%
sean
#7
130 c.
Top 24%
Europe2048
#8
133 c.
Top 28%
Natanaelel
#9
136 c.
Top 31%
cers
#10
139 c.
Top 34%
val
#11
140 c.
Top 38%
voytxt
#12
145 c.
Top 41%
Thomasdcrt
#13
150 c.
Top 45%
scpchicken
#14
162 c.
Top 52%
SephQ
Alex
#15
166 c.
Top 55%
Rag
#16
169 c.
Top 59%
smclaughlin-cf
#17
170 c.
Top 62%
davyboyh
#18
172 c.
Top 66%
maximec-indy
#19
174 c.
Top 69%
Pascal
#20
182 c.
Top 72%
XenThe
#21
186 c.
Top 76%
Mif712
#22
195 c.
Top 79%
ComputerKWasTaken
#23
200 c.
Top 83%
thaispalmer
#24
219 c.
Top 86%
KrausRaus
#25
258 c.
Top 90%
madeforlosers
#26
427 c.
Top 93%
Luke
#27
593 c.
Top 97%
jules
#28
606 c.
Top 100%
Arnaud