Skip to content
Open
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ npm-debug.log*

# OS artifacts
*.DS_Store
.idea

.idea

7 changes: 7 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/javascript-workbook.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

573 changes: 573 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

33 changes: 29 additions & 4 deletions 01week/rockPaperScissors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// Student: Jon Gorman
// Class: 211 JavaScript Tue/Thur
// Instructor: Renee Dudley
// Date: 10/10/17
//
//Make a function for rock paper scissors game
//function should include a way to check for a tie
//function should include a way to check for player one win
//function should include a way to check for player two win
//function should have a way to check that game is played correctly i.e.(no use of words other tha those needed for game
'use strict';

const assert = require('assert');
Expand All @@ -8,10 +18,21 @@ const rl = readline.createInterface({
});


function rockPaperScissors(hand1, hand2) {

// Write code here

function rockPaperScissors(a, b) {
// make variables that allow the function to pass the test ie. lowercase and whitespace.
const hand1 = a.toLowerCase().trim();
const hand2 = b.toLowerCase().trim();
//check for a tie
if (hand1 === hand2) {
return "It's a tie!";
// Write code here
// Check for hand one win
} else if (hand1 === 'rock' && hand2 === 'scissors' || hand1 === 'paper' && hand2 === 'rock' || hand1 === 'scissors' && hand2 === 'paper') {
return "Hand one wins!"
//Check for player two win
} else if (hand1 === 'rock' && hand2 === 'paper' || hand1 === 'paper' && hand2 === 'scissors' || hand1 === 'scissors' && hand2 === 'rock') {
return "Hand two wins!"
}
}

function getPrompt() {
Expand Down Expand Up @@ -49,3 +70,7 @@ if (typeof describe === 'function') {
getPrompt();

}
//"good programmers look both ways before crossing one way street"
//// else if (hand1 && hand2 !== 'rock', 'paper', 'scissors'){
// return "\sYour tryig to play a different game!\s"
// }
77 changes: 77 additions & 0 deletions 02week/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//student:Jon Gorman
//Assignment: Tests in rockPaperScissors
//Instructor: Reneee Dudley
//Date: 10/13/2017new change test
//
'use strict';

const assert = require('assert');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});


function rockPaperScissors(a, b) {
// make variables that allow the function to pass the test ie. lowercase and whitespace.
const hand1 = a.toLowerCase().trim();
const hand2 = b.toLowerCase().trim();

//check for a tie
if (hand1 === hand2) {
return "It's a tie!";
// Write code here
// Check for hand one win
} else if (hand1 === 'rock' && hand2 === 'scissors' || hand1 === 'paper' && hand2 === 'rock' || hand1 === 'scissors' && hand2 === 'paper') {
return "Hand one wins!"
//Check for player two win
} else if (hand1 === 'rock' && hand2 === 'paper' || hand1 === 'paper' && hand2 === 'scissors' || hand1 === 'scissors' && hand2 === 'rock') {
return "Hand two wins!"
}else {
return "You are not playing the game right!"
}
}

function getPrompt() {
rl.question('hand1: ', (answer1) => {
rl.question('hand2: ', (answer2) => {
console.log( rockPaperScissors(answer1, answer2) );
getPrompt();
});
});
}

// Tests

if (typeof describe === 'function') {
describe('#rockPaperScissors()', () => {
it('should detect a tie', () => {
assert.equal(rockPaperScissors('rock', 'rock'), "It's a tie!");
assert.equal(rockPaperScissors('paper', 'paper'), "It's a tie!");
assert.equal(rockPaperScissors('scissors', 'scissors'), "It's a tie!");
});
it('should detect which hand won', () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, you've tested for all possible win cases!

assert.equal(rockPaperScissors('rock', 'paper'), "Hand two wins!");
assert.equal(rockPaperScissors('paper', 'scissors'), "Hand two wins!");
assert.equal(rockPaperScissors('scissors', 'rock'), "Hand two wins!")
assert.equal(rockPaperScissors('rock', 'scissors'), "Hand one wins!");
assert.equal(rockPaperScissors('scissors', 'paper'), "Hand one wins!");
assert.equal(rockPaperScissors('paper', 'rock'), "Hand one 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!");
});
it('shoulde check for unassigned words', () => {
assert.equal(rockPaperScissors('rock', 'pippir'), "You are not playing the game right!");
assert.equal(rockPaperScissors('roiok', 'paper'), "You are not playing the game right!");
assert.equal(rockPaperScissors('roiock', 'poppir'), "You are not playing the game right!");
});
});
} else {

getPrompt();

}