Skip to content

Instantly share code, notes, and snippets.

@jacksonhenry3
Created September 25, 2013 04:43
Show Gist options
  • Save jacksonhenry3/6695241 to your computer and use it in GitHub Desktop.
Save jacksonhenry3/6695241 to your computer and use it in GitHub Desktop.
simple one way morse code translator
<html>
<link href='http://fonts.googleapis.com/css?family=Raleway:200' rel='stylesheet' type='text/css'>
<style>
body
{font-family: 'Raleway', sans-serif;
background-color: #E74C3C;
color:white;
text-align:center;
}
h1
{
font-size: 50px;
background-color: rgba(0,0,0,.4)
}
#result
{
font-size: 30px;
color:white;
font-weight: bold;
padding:25px;
}
</style>
<h1>Type the message to be translated in to morse code</h1>
<textarea id="myTextarea" rows="4" cols="50">Morse Code</textarea>
<div id = 'result'></div>
<script>
dictionary = {" ":" ","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":"----.",".":".-.-.-",",":"--..--",":":"---...","?":"..--..","'":".----.","-":"-....-","/":"-..-.","|":"-.--.-","\"":".-..-.","@":".--.-.","=":"-...-","\n":"\n","!":"!"};
function displayResult()
{
a = document.getElementById("myTextarea").value
b = ''
a = a.toUpperCase()
for (var i = 0; i < a.length; i++) {
b = b+dictionary[a[i]]+' '
};
document.getElementById("result").innerHTML = b
};
</script>
<button type="button" onclick="displayResult()">translate!</button>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment