body {
fontfamily: Arial, sansserif;
textalign: center;
margintop: 50px;
}
Welcome to our Morse Code translation website!
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',
'...': '.',
'..': ',',
'....': '?',
'..': '\'',
'..': '!',
'...': '/',
'..': '(',
'..': ')',
'....': '&',
'...': ':',
'...': ';',
'...': '=',
'...': ' ',
'....': '',
'...': '_',
'....': '"',
'.....': '$',
'...': '@',
'...': '\n',
'......': 'SOS'
};
const morseCodeTranslation = (morseCode) => {
return morseCode.split(' ')
.map(code => morseCodeMap[code] || ' ')
.join('');
}
const morseForm = document.getElementById('morseForm');
const translationResult = document.getElementById('translationResult');
morseForm.addEventListener('submit', function (event) {
event.preventDefault();
const morseCodeInput = document.getElementById('morseCodeInput').value.trim();
const translatedText = morseCodeTranslation(morseCodeInput);
translationResult.textContent = `Translated Text: ${translatedText}`;
});