diff --git a/01week/rockPaperScissors.js b/01week/rockPaperScissors.js index 72f0f1a89..69bef2a5c 100644 --- a/01week/rockPaperScissors.js +++ b/01week/rockPaperScissors.js @@ -11,13 +11,45 @@ const rl = readline.createInterface({ output: process.stdout }); + // the function that will be called by the unit test below const rockPaperScissors = (hand1, hand2) => { + // create hands than correct is it has lowercase or whitespace + // need to get white space away as well as lowercase the word + let scrubHand1 = hand1.toLowerCase().trim(); + +let scrubHand2 = hand2.toLowerCase().trim(); + +//need to compare hand1 to hand2 and if its the same its a tie +//I tried to replicate the whiteboading video but for some reason i wasn't able to achieve +if (scrubHand1 === scrubHand2){ + return "It's a tie!" + } +if (scrubHand1 === "rock" && scrubHand2 === "paper"){ + return 'Hand two wins!' +} - // Write code here - // Use the unit test to see what is expected +if (scrubHand1 === "rock" && scrubHand2 === "scissors"){ + return 'Hand one wins!' +} +if (scrubHand1 === "paper" && scrubHand2 === "rock"){ + return "Hand one wins!" +} +if (scrubHand1 === "paper" && scrubHand2 === "scissors"){ + return 'Hand two wins!' } +if (scrubHand1 === "scissors" && scrubHand2 === "rock"){ + return "Hand two wins!" +} +if (scrubHand1 === "scissors" && scrubHand2 === "paper"){ + return "Hand one wins!" +} +} + + + + // the first function called in the program to get an input from the user // to run the function use the command: node main.js diff --git a/02week/pigLatin.js b/02week/pigLatin.js index 7f2b58a8a..c3fdd085c 100644 --- a/02week/pigLatin.js +++ b/02week/pigLatin.js @@ -7,10 +7,29 @@ const rl = readline.createInterface({ output: process.stdout }); - const pigLatin = (word) => { +//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){ + //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; +} - // Your code here } diff --git a/02week/practice.js b/02week/practice.js new file mode 100644 index 000000000..c5328b5df --- /dev/null +++ b/02week/practice.js @@ -0,0 +1,38 @@ +'use strict' + +let word = "elephant"; +let vowels = "aeiou"; + + + +function firstVowel(word){ + //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(answer === true){ + return i; + } + } +} + +let position = firstVowel("christopher"); +console.log("position of the first vowel", position); + + + + + + +// Pig Latin +// 1. find the first vowel +// if the first letter 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 yay to the end +// fox -> f ox -> oxf -> oxfay +// if the word does not have a vowel, you can make something up \ No newline at end of file