Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 36 additions & 17 deletions 01week/rockPaperScissors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand All @@ -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 {
Expand Down
Empty file added 02week/pigLatin/pigLatin.css
Empty file.
21 changes: 21 additions & 0 deletions 02week/pigLatin/pigLatin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Pig Latin</title>
<link rel="stylesheet" href="pigLatin.css">
</head>
<body>
<div class="container">
<h1>Pig Latin Generator</h1>
<p>Enter in any word and generate pig latin</p>
<input type="text" placeholder="Submit" id="button" onclick="pigLatin()">
<p id="text"></p>
</div>


<script src="pigLatin.js"></script>
</body>
</html>
72 changes: 72 additions & 0 deletions 02week/pigLatin/pigLatin.js
Original file line number Diff line number Diff line change
@@ -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();

// }