diff --git a/01week/rockPaperScissors.js b/01week/rockPaperScissors.js index 1cc99aab8..2a1a49eb0 100644 --- a/01week/rockPaperScissors.js +++ b/01week/rockPaperScissors.js @@ -12,20 +12,26 @@ function rockPaperScissors(cleanHand1, cleanHand2){ let hand1 = cleanHand1.trim().toLowerCase(); let hand2 = cleanHand2.trim().toLowerCase(); - if (hand1 == 'rock' && hand2 == 'scissors'){ - return "Hand one wins!"; + if (hand1 == 'rock' && hand2 =='scissors'){ + return 'hand1 wins!'; } else if (hand1 == 'rock' && hand2 == 'paper'){ - return "Hand two wins!"; - } else if (hand1 == 'paper' && hand2 == 'rock'){ - return "Hand one wins!"; + return 'hand2 wins!'; + } else if (hand1 == 'rock' && hand2 == 'rock'){ + return "It's a tie!"; } else if (hand1 == 'paper' && hand2 == 'scissors'){ - return "Hand two wins!"; - } else if (hand1 == 'scissors' && hand2 == 'paper'){ - return "Hand one wins!"; - } else if (hand1 == 'scissors' && hand2 == 'rock'){ - return "Hand two wins!"; - } else if (hand1 == hand2){ + return 'hand2 wins!'; + } else if (hand1 == 'paper' && hand2 == 'rock'){ + return 'hand1 wins!' ; + } else if (hand1 == 'paper' && hand2 == 'paper'){ + return "It's a tie!"; + } else if (hand1 == 'scissors' && hand2 == 'scissors'){ return "It's a tie!"; + } else if (hand1 == 'scissors' && hand2 == 'rock'){ + return 'hand2 wins!'; + } else if (hand1 =='scissors' && hand2 == 'paper'){ + return 'hand1 wins!'; + } else { + return 'Please enter rock, paper, or scissors' } } @@ -49,14 +55,27 @@ if (typeof describe === 'function') { assert.equal(rockPaperScissors('scissors', 'scissors'), "It's a tie!"); }); it('should detect which hand won', () => { - assert.equal(rockPaperScissors('rock', 'paper'), "Hand two wins!"); - assert.equal(rockPaperScissors('paper', 'scissors'), "Hand two wins!"); - assert.equal(rockPaperScissors('rock', 'scissors'), "Hand one wins!"); + assert.equal(rockPaperScissors('rock', 'paper'), "hand2 wins!"); + assert.equal(rockPaperScissors('paper', 'scissors'), "hand2 wins!"); + assert.equal(rockPaperScissors('scissors', 'rock'), "hand2 wins!"); + }); + it('should detect which hand won', () => { + assert.equal(rockPaperScissors('paper', 'rock'), "hand1 wins!"); + assert.equal(rockPaperScissors('scissors', 'paper', ), "hand1 wins!"); + assert.equal(rockPaperScissors('rock', 'scissors'), "hand1 wins!"); }); it('should scrub input to ensure lowercase with "trim"ed whitepace', () => { - assert.equal(rockPaperScissors('rOcK', ' paper '), "Hand two wins!"); - assert.equal(rockPaperScissors('Paper', 'SCISSORS'), "Hand two wins!"); - assert.equal(rockPaperScissors('rock ', 'sCiSsOrs'), "Hand one wins!"); + assert.equal(rockPaperScissors('rOcK', ' paper '), "hand2 wins!"); + assert.equal(rockPaperScissors('Paper', 'SCISSORS'), "hand2 wins!"); + assert.equal(rockPaperScissors('sCiSsOrs ', ' rOck '), "hand2 wins!"); + }); + it('should scrub input to ensure lowercase with "trim"ed whitepace', () => { + assert.equal(rockPaperScissors(' paper ', 'rOcK'), "hand1 wins!"); + assert.equal(rockPaperScissors('SCISSORS', 'Paper'), "hand1 wins!"); + assert.equal(rockPaperScissors(' rOck ', 'sCiSsOrs '), "hand1 wins!"); + }); + it('Test to make sure user must input a valid entry (e.g. \'rock\', \'paper\', or \'scissors\')', () => { + assert.equal(rockPaperScissors(' BANANA', 'rappleOcK'), 'Please enter rock, paper, or scissors'); }); }); } else { diff --git a/02week/pigLatin/pigLatin.css b/02week/pigLatin/pigLatin.css new file mode 100644 index 000000000..e69de29bb diff --git a/02week/pigLatin/pigLatin.html b/02week/pigLatin/pigLatin.html new file mode 100644 index 000000000..ccc65484a --- /dev/null +++ b/02week/pigLatin/pigLatin.html @@ -0,0 +1,21 @@ + + + + + + + Pig Latin + + + +
+

Pig Latin Generator

+

Enter in any word and generate pig latin

+ +

+
+ + + + + \ No newline at end of file diff --git a/02week/pigLatin/pigLatin.js b/02week/pigLatin/pigLatin.js new file mode 100644 index 000000000..e7e87f1ba --- /dev/null +++ b/02week/pigLatin/pigLatin.js @@ -0,0 +1,72 @@ +// 'use strict'; + +// const assert = require('assert'); +// const readline = require('readline'); +// const rl = readline.createInterface({ +// input: process.stdin, +// output: process.stdout +// }); + +function pigLatin(word) { + // Convert string to lowercase + word = word.trim().toLowerCase(); + // Initialize array of vowels + const vowels = ["a", "e", "i", "o", "u"]; + // Initialize vowel index to 0 + let vowelIndex = 0; + + if (vowels.includes(word[0])) { + // If first letter is a vowel + document.getElementById("text").innerHTML = word + "yay"; + } else { + // If the first letter isn't a vowel i.e is a consonant + for (let char of word) { + // Loop through until the first vowel is found + if (vowels.includes(char)) { + // Store the index at which the first vowel exists + vowelIndex = word.indexOf(char); + break; + } + } + // Compose final string + document.getElementById("text").innerHTML = word.slice(vowelIndex) + word.slice(0, vowelIndex) + "ay"; + } +} + + +// function getPrompt() { +// rl.question('word ', (answer) => { +// console.log( pigLatin(answer) ); +// getPrompt(); +// }); +// } + +// Tests + +// if (typeof describe === 'function') { + +// describe('#pigLatin()', () => { +// it('should translate a simple word', () => { +// assert.equal(pigLatin('car'), 'arcay'); +// assert.equal(pigLatin('dog'), 'ogday'); +// }); +// it('should translate a complex word', () => { +// assert.equal(pigLatin('create'), 'eatecray'); +// assert.equal(pigLatin('valley'), 'alleyvay'); +// }); +// it('should attach "yay" if word begins with vowel', () => { +// assert.equal(pigLatin('egg'), 'eggyay'); +// assert.equal(pigLatin('emission'), 'emissionyay'); +// }); +// it('should lowercase and trim word before translation', () => { +// assert.equal(pigLatin('HeLlO '), 'ellohay'); +// assert.equal(pigLatin(' RoCkEt'), 'ocketray'); +// }); +// }); +// } else { + +// getPrompt(); + +// } + +