Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pigLatinEncode()
- {
- var message = document.getElementById("piglatinmessage").value;
- var words = message.split(" ");
- var encoded = [];
- var counter = 0;
- words.forEach(function(value, index){
- if(vowels.includes(value[0]))
- {
- value = value + "yay";
- encoded.push(value);
- }
- else if(consonants.includes(value[0]))
- {
- for(var i=0; i<value.length; i++)
- {
- if(vowels.includes(value[i]))
- {
- break
- }
- }
- var last = value.substring(0, i);
- var first = value.slice(i);
- var value = first + last + "ay";
- encoded.push(value);
- }
- else
- {
- alert("Input must be one word made up of letters only!")
- }
- });
- document.getElementById("piglatin-output-text").innerHTML = encoded.join(" ");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement