🚀 Introduction
Morse code is one of the oldest communication systems, but it’s still a fun and practical concept to explore—especially for developers. In this post, we’ll build a simple Morse code translator using JavaScript that can convert text into Morse code.
📡 What is Morse Code?
Morse code represents characters using dots (.) and dashes (-). Each letter and number has a unique pattern, which makes it possible to encode and decode messages.
🧠 Step 1: Create a Morse Code Map
First, define a mapping object:
const morseCodeMap = {
A: ".-", B: "-...", C: "-.-.", D: "-..", E: ".",
F: "..-.", G: "--.", H: "....", I: "..", J: ".---",
K: "-.-", L: ".-..", M: "--", N: "-.", O: "---",
P: ".--.", Q: "--.-", R: ".-.", S: "...", T: "-",
U: "..-", V: "...-", W: ".--", X: "-..-", Y: "-.--", Z: "--..",
0: "-----", 1: ".----", 2: "..---", 3: "...--",
4: "....-", 5: ".....", 6: "-....", 7: "--...",
8: "---..", 9: "----."
};
⚙️ Step 2: Convert Text to Morse Code
function textToMorse(text) {
return…