From 51265bae3af0b0535a159922390d8d5cce70abf1 Mon Sep 17 00:00:00 2001 From: Chris Trevino Date: Mon, 8 Jun 2020 21:07:47 -0500 Subject: [PATCH 1/2] starting --- 02week/pigLatin.js | 26 +++++++++++++++++++++++++- 02week/tests.js | 1 + 03week/ticTacToe.js | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/02week/pigLatin.js b/02week/pigLatin.js index 7f2b58a8a..4ac81e58f 100644 --- a/02week/pigLatin.js +++ b/02week/pigLatin.js @@ -7,11 +7,35 @@ 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 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 - + let position = firstVowel(word); + console.log("position of the first vowel is", position) + } 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() { From 1fa523a17f086cf953e6710a48ebf69d80caaf3d Mon Sep 17 00:00:00 2001 From: Chris Trevino Date: Sun, 14 Jun 2020 21:31:07 -0500 Subject: [PATCH 2/2] finished --- 02week/PigLatin.txt | 7 +++++++ 02week/pigLatin.js | 26 ++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 02week/PigLatin.txt 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 4ac81e58f..256306dbe 100644 --- a/02week/pigLatin.js +++ b/02week/pigLatin.js @@ -10,6 +10,7 @@ const rl = readline.createInterface({ //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++){ @@ -18,7 +19,7 @@ function firstVowel(word){ //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); + //console.log(i , " ", answer); //if our answer is = to true it would return our i. if(answer === true){ return i; @@ -33,10 +34,27 @@ function firstVowel(word){ 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) - -} + //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 = () => {