Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                 <div class="main-whatif">
  <div class="whatif">
    <h1 class="heading">Text to Morse Code And Morse Code to Text</h1>
    <div class="container">
      <textarea name="" id="code" cols="30" rows="10">Type Here</textarea>
      
      <div class="buttons">
        <button id="morseToText">Convert Morce Code To Text</button>
        <button id="clear">Reset</button>
        <button id="textToMorse">Convert Text to Morse Code</button>
        
        </div>
      
  <div id="result"></div> 
      
      <a href="https://morsecoder.org"  class="allok" target="_blank"><b>Morse Code Translator</a>

              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Nunito');
*{
  margin:0;
  padding:0;
  box-sizing: border-box;
}
body{
  color: black;
  background-color: pink;
  font-family: 'Nunito', sans-serif;
}
.main-whatif{
  display:flex;
  flex-direction:column;
  align-items:center;
}
.whatif{
  display:flex;
  flex-direction:column;
  align-items:center;
  height:70vh;
  width:100%;
  
}
.heading{
  height:40vh;
  display:flex;
  align-items:center;
}
.container{
  height:50vh;
  width:100%;
  display:flex;
  flex-direction:column;
  justify-content:space-around;
  align-items:center;
}

#code{
  width:50%;
  height:60%;
  outline: none;
  background-color:black;
  font-size:18px;
  color: white;

}
.buttons{
  display:flex;
  justify-content:center;
}

button{
  background:#blue;
  padding:10px;
  text-decoration: none;
  font-size: 17px;
  margin:25px;
  text-transform: uppercase;
  border: 2px solid #green;
  cursor: pointer;
  border-radius: 20px;
  
}
button:hover{
  background:#3c2e3d;
  border:none;
  color:#dae9e4;
  text-shadow: 0px 0px 6px rgba(255, 255, 255, 1);
  -webkit-box-shadow: 0px 5px 40px -10px rgba(0,0,0,0.57);
  -moz-box-shadow: 0px 5px 40px -10px rgba(0,0,0,0.57);
  transition: all .5s ease ;
}

#result{
  text-align:center;
  font-size:30px;
  width:50%;
}

.allok
{
  background-color: blue;
  padding: 7px;
  color:white;
  border-radius:15px;
  border-radius: 20px;
}
              
            
!

JS

              
                const morseCode = {
  "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":"----.",
  " ":" ",
  ".":".-.-.-",
  ",":"--..--",
  "?":"..--..",
  "'":".----.",
  "(":"-.--.",
  ")":"-.--.-",
  ":":"---...",
  "=":"-...-",
  "+":".-.-.",
  "-":"-....-",
  "_":"..--.-",
  "@":".--.-."
};

const textToMorse = document.getElementById("textToMorse");
const morseToText = document.getElementById("morseToText");
const clear = document.getElementById("clear");


textToMorse.addEventListener("click",textMorse);
morseToText.addEventListener("click",morseText);
clear.addEventListener("click",function(){
  document.getElementById("code").value=" ";
  document.getElementById("result").textContent=" ";
})

function textMorse(){
    let text = document.getElementById("code").value;
    text = text.toLowerCase();
    console.log(text);
    let output = " ";
    for(let i = 0; i < text.length; i++){
      output += morseCode[text.charAt(i)];
      output += " ";
    }
    document.getElementById("result").textContent = output;
}

function morseText(){
  let text = document.getElementById("code").value;
  let output = " ";
  let arr = text.split(' ').map(function(val){
    for(var key in morseCode){
      if(val === morseCode[key]){
        output+=key;
      }
    }
    document.getElementById("result").textContent = output;
  });
}
              
            
!
999px

Console