diff --git a/02week/pigLatin.js b/02week/pigLatin.js index 046434c94..811edc017 100644 --- a/02week/pigLatin.js +++ b/02week/pigLatin.js @@ -6,15 +6,28 @@ const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); +/* I need at least two more functions to meet the benchmarks for this assignment. I will probably complete this and then find out there's a bunch of bugs and a way easier way, but leggo. */ +/*Based on the tests, I need at least three functions. One of which will probably be specifically to address the vowel test. Would probably be best to use an if statement to look for vowels at the beginning of my chosen word, or in this case, a bunch of string. IF the word matches the criteria, then I will have it return the word+way. */ +/* For any other words, it seems intuitive just to use a function that moves the first letter to the end of the word (maybe using an array method?) and then adding ay.*/ +/* The first function below splits the word or string into an array of substrings, which allows the following functions to move letters (which now make up the new array) around. */ +/* It seems like maybe a good idea to establish string as a global variable so it can be used for all functions without having to re-write it for each function*/ +function splitWordIntoArray(word) { + return word.split('') +} function pigLatin(word) { - - // Your code here - + const vowelArray = ["a", "e", "i", "o", "u"] + if (vowelArray.includes(word[0])) { + console.log("firstIsVowel") + return word+"way"; + }else { + console.log("firstNotVowel") + const chars = splitWordIntoArray(word) + return chars.slice(1).join('') + chars[0] + 'ay'; + } } - function getPrompt() { rl.question('word ', (answer) => { console.log( pigLatin(answer) );