diff --git a/02week/PigLatin.txt b/02week/PigLatin.txt new file mode 100644 index 000000000..2cb6faa11 --- /dev/null +++ b/02week/PigLatin.txt @@ -0,0 +1,7 @@ +1. find the first vowel +// if the first is a vowel, then you add "yay" to the end. +// example: egg -> eggyay +// if the first vowel is in the middle of the word, +// then you split the word, and swap the halves, and add "ay" to the end. +fox -> f ox -> oxf -> oxfay +//if the word doesnt have a vowel, you can make something up diff --git a/02week/pigLatin.js b/02week/pigLatin.js index 7f2b58a8a..256306dbe 100644 --- a/02week/pigLatin.js +++ b/02week/pigLatin.js @@ -7,12 +7,54 @@ const rl = readline.createInterface({ output: process.stdout }); +//this function will take in a word and returns the position of the first vowel +//if the word has no vowel, it return -1 +function firstVowel(word){ + let wordNew = word.toLowerCase().trim(); + let vowels = "aeiou"; + //loops thru whatever word is chosen to get translated + for(let i = 0; i < word.length; i++){ + //needed to find a way to go thru every individual letter + let letter = word[i]; + //needed to create the answer. this tells us wether it has a vowel or not + let answer = vowels.includes(letter); + //console.log(letter, " ", answer); + //console.log(i , " ", answer); + //if our answer is = to true it would return our i. + if(answer === true){ + return i; + }//is this letter a vowel + } + //if you get to this point + //what does it mean? is it done running the loop, and did not return + //which means it did not find a vowel + return -1; +} const pigLatin = (word) => { // Your code here + + //set a empty string + //set the first vowel into a variable + let position = firstVowel(word); + //console.log("position of the first vowel is", position) + //felt like it should have worked + if (firstVowel == true){ + word += "yay"; + return word; + } else if (firstVowel === -1){ + let firstHalf = word.substring(0, position); + word = word.substring(firstVowel, word.length); + word = word + firstHalf; + word += "ay"; + return word; + + } + + +} -} const getPrompt = () => { diff --git a/02week/tests.js b/02week/tests.js index e69de29bb..fa761ffe8 100644 --- a/02week/tests.js +++ b/02week/tests.js @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/03week/ticTacToe.js b/03week/ticTacToe.js index 1abf5b900..092e51bdf 100644 --- a/03week/ticTacToe.js +++ b/03week/ticTacToe.js @@ -25,6 +25,7 @@ function printBoard() { function horizontalWin() { // Your code here + } function verticalWin() {