main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function PigLatinTranslator(answer) {
  var vowel1 = answer.match(/[aeiouyAEIOUY]/).index;
  var step1 = answer.substring(vowel1);
  var step2 = answer.substring(0, vowel1);
  if (step2.length === 0) {
    return step1 + step2 + 'yay';
  } else return step1 + step2 + 'ay';
}

var input = window.prompt('enter the word(s) you want translated');
var output = '';
var wordlist = input.split(' ');
for (var words = 0; words < wordlist.length; words++) {
  output = output + PigLatinTranslator(wordlist[words]);
  output = output + ' ';
}
var speak = window.speechSynthesis;

speak.speak(new SpeechSynthesisUtterance(output));
alert(output);
Native Browser JavaScript