DEV Community

Morse Zone
Morse Zone

Posted on

Building a Morse Code Practice Timer in JavaScript: Timing Dits, Dahs and Gaps

Learning Morse code is not only about memorising dots and dashes. It is about rhythm. If your timing is uneven, even a perfectly remembered letter can sound like something else. That is why a small practice timer is such a useful first project: it turns an abstract rule into something you can hear, see and feel.

The standard timing is beautifully simple. Think of one short unit as your base. A dit lasts one unit, a dah lasts three units, the gap between elements inside a letter is one unit, the gap between letters is three units, and the gap between words is seven units. Once you fix the length of one unit, everything else follows. At a slow practice speed, one unit might be 200 milliseconds. At a faster speed, it might be only 80 milliseconds, but the ratios stay the same.

A setInterval-based timer makes this easy to build in JavaScript. Start with a variable for the unit length and a queue of signals. Each signal is either a dit, a dah or a gap, with a duration measured in units. Use setInterval to step through the queue, or use setTimeout for each step, and show the current letter on screen while a short beep or a visual flash plays. Add controls for speed, a start and stop button, and a display that highlights each element as it plays. Keep the code small at first: a function to convert a word into signals, a function to play one signal, and a function to move to the next.

Try this short drill. Set one unit to 200 milliseconds and practise the word SOS, then the word HI, then the word CQ. Listen first without looking, then check the letters, then repeat the same words slightly faster. Notice where you rush: most beginners shorten the gap between letters, which makes separate letters run together. Slowing down that gap often improves readability more than speeding up the dits and dahs.

For reference while you practise, keep a morse code alphabet chart nearby and explore the tools at Morse Zone. A timer will not teach you every letter on its own, but it will teach you the timing habit that makes every letter clearer.

Top comments (0)