diff --git a/index.html b/index.html index 8f536de8..1c36be75 100644 --- a/index.html +++ b/index.html @@ -10,6 +10,7 @@

Hello World!


+
diff --git a/main.js b/main.js index 1c92f304..7aa94714 100644 --- a/main.js +++ b/main.js @@ -10,8 +10,48 @@ const rl = readline.createInterface({ output: process.stdout }); + let word = "" + + + const pigLatin = (word) => { + // list the vowels: a, e, i, o, u + let vowels = ["a", "e", "i", "o", "u"]; + let finalWord = ""; + // scrub the data + let cleanWord = word.toLowerCase().trim(); + // if word begins with vowel add 'yay' + if (vowels.indexOf(cleanWord[0]) > -1) { + finalWord = cleanWord + "yay"; + return finalWord; + } + // if word begins with consonant + else { + // run through string until we find the first vowel. What match() does is it returns an array of all the character indexes that match our regular expression pattern. Our pattern looks at any character that is a vowel. If there are no vowels, then we assign firstMatch the value of 0. + let firstMatch = cleanWord.match(/[aeiou]/g) || 0; + // index of the first vowel found in the string using indexOf() + let vowelIndex = cleanWord.indexOf(firstMatch[0]); + //string without the consonant beginning + the consonant + ay + finalWord = cleanWord.substring(vowelIndex) + cleanWord.substring(0, vowelIndex) + "ay"; + return finalWord; + } +}; + + +for (let i = 0; i < word.length; i++){ + for(let i=1; i { // Your code here @@ -68,4 +108,4 @@ if (typeof describe === 'function') { // break your code into pieces and focus on one piece at a time... // 1. if word begins with a vowel send to one function: adds "yay" // 2. if word begins in with a consonant send to another function: splices off beginning, returns word with new ending. -// 3. if multiple words, create array of words, loop over them, sending them to different functions and creating a new array with the new words. \ No newline at end of file +// 3. if multiple words, create array of words, loop over them, sending them to different functions and creating a new array with the new words \ No newline at end of file