Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ <h1>Instructions</h1>
<h1>Translation</h1>
<div id="result"></div>
</section>

<script type="text/javascript" src="js/morse.js"></script>
<div id = "MC" src="morseCode.js"></div>
<script type="text/javascript" src="./morseCode.js"></script>
<!--
<script type="text/javascript" src="js/morse.js"></script>
-->
</body>
</html>
70 changes: 70 additions & 0 deletions morseCode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
var reply;
var translatedReply;
var spacedOut;

var display = document.getElementById("result");

var morse = {
'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' : '--..',
'1' : '.----',
'2' : '..---',
'3' : '...--',
'4' : '....-',
'5' : '.....',
'6' : '-....',
'7' : '--...',
'8' : '---..',
'9' : '----.',
'0' : '-----',
'.' : '.-.-.-',
',' : '--..--',
'?' : '..--..',
'/' : '-..-.',
' ' : '|'
};

function prompter(){
reply = prompt("What text do you want translated?");
reply = reply.toLowerCase();
}

function translate(spacedOut){
return morse[spacedOut];
}

function printTranslate(){
spacedOut = reply.split("").map(translate).join(" ");
display.innerHTML = spacedOut;

}

prompter();
printTranslate();
console.log(reply);
console.log(spacedOut);