diff --git a/.gitignore b/.gitignore index 2973ab0b9..90d07989f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,6 @@ npm-debug.log* # OS artifacts *.DS_Store -.idea \ No newline at end of file + +.idea + diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 000000000..db8c7d583 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/javascript-workbook.iml b/.idea/javascript-workbook.iml new file mode 100644 index 000000000..24643cc37 --- /dev/null +++ b/.idea/javascript-workbook.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..24eb271ab --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..316e76d3b --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..94a25f7f4 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 000000000..334cd079a --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,573 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + false + true + true + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1507254634169 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/01week/rockPaperScissors.js b/01week/rockPaperScissors.js index 16f58790a..f0477395d 100644 --- a/01week/rockPaperScissors.js +++ b/01week/rockPaperScissors.js @@ -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'); @@ -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() { @@ -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" +// } \ No newline at end of file diff --git a/02week/tests.js b/02week/tests.js index e69de29bb..ec485ea23 100644 --- a/02week/tests.js +++ b/02week/tests.js @@ -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', () => { + 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(); + +} \ No newline at end of file