Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function pigLatinEncode()
  2. {
  3.     var message = document.getElementById("piglatinmessage").value;
  4.     var words = message.split(" ");
  5.     var encoded = [];
  6.     var counter = 0;
  7.     words.forEach(function(value, index){
  8.     if(vowels.includes(value[0]))
  9.     {
  10.         value = value + "yay";
  11.         encoded.push(value);
  12.     }
  13.     else if(consonants.includes(value[0]))
  14.     {
  15.         for(var i=0; i<value.length; i++)
  16.         {
  17.             if(vowels.includes(value[i]))
  18.             {
  19.                 break
  20.             }
  21.         }
  22.         var last = value.substring(0, i);
  23.         var first = value.slice(i);
  24.         var value = first + last + "ay";
  25.         encoded.push(value);
  26.     }
  27.     else
  28.     {
  29.         alert("Input must be one word made up of letters only!")
  30.     }
  31.     });
  32.     document.getElementById("piglatin-output-text").innerHTML = encoded.join(" ");
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement