diff --git a/main.js b/main.js index 282f4c93..f71943a5 100644 --- a/main.js +++ b/main.js @@ -11,9 +11,46 @@ const rl = readline.createInterface({ }); + const pigLatin = (word) => { +word = word.toLowerCase().trim() + +console.log("Your first letter is " + word [0]) + + +let firstletter = word[0] +let vowels = ["a", "e", "i", "o", "u"] +let vowelPosition = 0 + +//If it starts with a vowel just add "yay" + +if(vowels.includes( firstletter ) == true) +{ + return word + "yay" +//it is a vowel +} + +else{ + + //not a vowel - // Your code here + for (let index = 0; index < word.length; index = index + 1) { + + if(vowels.includes(word[index])){ + +vowelPosition = index + +break; + } +//check each letter to see how many consonants there are in a row + + } + + + let finalAnswer = word.slice(vowelPosition) + word.slice(0, vowelPosition) + "ay" + return finalAnswer + +} }