Giter VIP home page Giter VIP logo

morse-translator's Introduction

Morse-translator

Code by anmabe06

(Code variables are in spanish)

This is a morse to text, and text to morse translator

This is a step by step guide on how to do it:

  1. Define the alphabet (Morse and "Normal") in two different arrays:

    var codigoMorse = ['.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....', '..', '.---', '-.-', '.-..', '--', '-.', '--.--', '---', '.--.', '--.-', '.-.', '...', '-',      '..-', '...-', '.--', '-..-', '-.--', '--..', '.----', '..---', '...--', '....-', '.....', '-....', '--...', '---..', '----.', '-----', '/', ' '];
    
    var codigoTexto = ['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', ' ', ''];
    
    
  2. Create a function to translate text to morse code:

    function traductorTextoMorse(cadena){
      var auxiliar = '';
      letras = cadena.split('');
    
      for(i = 0; i < letras.length; i++){
        var index = codigoTexto.indexOf(letras[i]);
        auxiliar = auxiliar + codigoMorse[index] + " ";
      }
      console.log(auxiliar);
    }
    
  3. Create a function to translate morse code to text:

    function traductorMorseTexto(cadena){
      var auxiliar = '';
      caracteres = cadena.split(' ');
    
      for(i = 0; i < caracteres.length; i++){
        var index = codigoMorse.indexOf(caracteres[i]);
        auxiliar = auxiliar + codigoTexto[index];
      }
      console.log(auxiliar);
    }
    
  4. Create a recursive function to initialize the program:

        function start(){
    var choose = prompt("Qué quieres traducir?\n Morse --> Texto [1]\n Texto --> Morse [2]\n\n");
    
       switch(choose){
         case "1":
           var input = prompt("Introduce el código (caracteres separados por un espacio; cadenas separadas por /)");
           traductorMorseTexto(input);
           console.log('\n___________________________\n\n');
           break;
    
         case "2":
           var input = prompt("Introduce la cadena\n");
           input = input.toLowerCase();
           traductorTextoMorse(input);
           console.log('\n___________________________\n\n');
           break;
    
         default:
           console.log('\n___________________________\n\n');
           console.log("\nPor favor, selecciona 1 o 2");
           break;
        }
        start();
       }
    
    
  5. Call the function:

    start();
    
    
  6. Translate!

morse-translator's People

Contributors

anmabe06 avatar

Stargazers

Alex M. avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.