// For morse translation var jj = 0; function MorseTranslator() { var msgInput = document.getElementById("msgInput"); var msgOutput = document.getElementById("msgOutput"); // to play the sound when the key is pressed if (msgInput.value[jj] == ".") { playSound('sine', 700, 0.1); } else if (msgInput.value[jj] == "-") { playSound('sine', 600, 0.3); } // to check if the given input is morse code or not if (isMorseCode(msgInput.value) == true) { if (msgInput.value[jj] == " ") { var decoded = morse.decode(msgInput.value); msgOutput.value = decoded; } } else { var encoded = morse.encode(msgInput.value); msgOutput.value = encoded; } jj = msgInput.value.length; if (jj == 0) { msgOutput.value = " "; } } function isMorseCode(str) { for (var i = 0; i < str.length; i++) if (['/', '-', '.', ' '].indexOf(str.charAt(i)) == -1) return false; return true; } function playFullTone(input) { for (var i = 0; i < input.value.length; i++) { if (input.value[i] == ".") { setTimeout(playSound('sine', 700, 0.1),2000); } else if (input.value[i] == "-") { setTimeout(playSound('sine', 600, 0.3),2000); } else { setTimeout(playSound('sine',0,0.5),2000); } } }