From 8f9cebc3c324e5015c2a428c31fb6b5ad14e4f2c Mon Sep 17 00:00:00 2001 From: James Messina Date: Sun, 24 Jan 2021 13:42:40 -0600 Subject: [PATCH 1/3] functions working --- index.html | 4 ++-- main.js | 43 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/index.html b/index.html index 8f536de8..b0222f8f 100644 --- a/index.html +++ b/index.html @@ -2,14 +2,14 @@ - + RPS Game

Hello World!


+

-
diff --git a/main.js b/main.js index 72f0f1a8..d3e9ca49 100644 --- a/main.js +++ b/main.js @@ -11,17 +11,44 @@ const rl = readline.createInterface({ output: process.stdout }); -// the function that will be called by the unit test below -const rockPaperScissors = (hand1, hand2) => { +function displayDate(){ + let d = new Date(); + document.getElementById("display-element").innerHTML = d; + console.log(d); +} + +function rockPaperScissors(hand1, hand2){ + + if(typeof hand1 !== 'string' || typeof hand2 !== 'string'){ + return 'try again'; + } - // Write code here - // Use the unit test to see what is expected + if((hand1.trim().toLowerCase() !== 'scissors' && hand1.trim().toLowerCase() !== 'paper' && hand1.trim().toLowerCase() !== 'rock') || (hand2.trim().toLowerCase() !== 'scissors' && hand2.trim().toLowerCase() !== 'paper' && hand2.trim().toLowerCase() !== 'rock')){ + return 'try again!'; + } + + if(hand1.trim().toLowerCase() === hand2.trim().toLowerCase()){ + return 'It\'s a tie!'; + }else if(hand1.trim().toLowerCase() === 'rock' && hand2.trim().toLowerCase() === 'scissors'){ + return 'Hand one wins!'; + }else if(hand1.trim().toLowerCase() === 'rock' && hand2.trim().toLowerCase() === 'paper'){ + return 'Hand two wins!'; + }else if(hand1.trim().toLowerCase() === 'paper' && hand2.trim().toLowerCase() === 'rock'){ + return 'Hand one wins!'; + }else if(hand1.trim().toLowerCase() === 'paper' && hand2.trim().toLowerCase() === 'scissors'){ + return 'Hand two wins!'; + }else if(hand1.trim().toLowerCase() === 'scissors' && hand2.trim().toLowerCase() === 'paper'){ + return 'Hand one wins!'; + }else if(hand1.trim().toLowerCase() === 'scissors' && hand2.trim().toLowerCase() === 'rock'){ + return 'Hand two 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 -// to close it ctrl + C +let r = rockPaperScissors('rock', 'scissors'); +console.log(r); + + function getPrompt() { rl.question('hand1: ', (answer1) => { rl.question('hand2: ', (answer2) => { @@ -59,4 +86,4 @@ if (typeof describe === 'function') { // always returns ask the user for another input getPrompt(); -} +} \ No newline at end of file From 4cf5e08b041d1803677f82ec42d54da07e4f41a0 Mon Sep 17 00:00:00 2001 From: James Messina Date: Sun, 24 Jan 2021 13:52:00 -0600 Subject: [PATCH 2/3] functions completed and working --- main.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index d3e9ca49..ca07eaa2 100644 --- a/main.js +++ b/main.js @@ -18,16 +18,18 @@ function displayDate(){ } function rockPaperScissors(hand1, hand2){ - + + //if either hand isnt a string, return 'try again' if(typeof hand1 !== 'string' || typeof hand2 !== 'string'){ return 'try again'; } + //if hand1 or hand2 is not 'rock', 'paper', 'scissors', then try again if((hand1.trim().toLowerCase() !== 'scissors' && hand1.trim().toLowerCase() !== 'paper' && hand1.trim().toLowerCase() !== 'rock') || (hand2.trim().toLowerCase() !== 'scissors' && hand2.trim().toLowerCase() !== 'paper' && hand2.trim().toLowerCase() !== 'rock')){ return 'try again!'; } - + //if both hands are the same then return 'its a tie' if(hand1.trim().toLowerCase() === hand2.trim().toLowerCase()){ return 'It\'s a tie!'; }else if(hand1.trim().toLowerCase() === 'rock' && hand2.trim().toLowerCase() === 'scissors'){ From 50769a0a11c696bce9f44e1424a3ae406f6241d1 Mon Sep 17 00:00:00 2001 From: James Messina Date: Wed, 3 Feb 2021 16:03:11 -0600 Subject: [PATCH 3/3] additional tests added --- main.js | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index ca07eaa2..8cb36ae3 100644 --- a/main.js +++ b/main.js @@ -21,7 +21,7 @@ function rockPaperScissors(hand1, hand2){ //if either hand isnt a string, return 'try again' if(typeof hand1 !== 'string' || typeof hand2 !== 'string'){ - return 'try again'; + return 'try again!'; } //if hand1 or hand2 is not 'rock', 'paper', 'scissors', then try again @@ -83,6 +83,41 @@ if (typeof describe === 'function') { assert.equal(rockPaperScissors('rock ', 'sCiSsOrs'), "Hand one wins!"); }); }); + + //additional tests + + describe('rps unit test assignment', function(){ + it('should properly handle whitespace before or afer input', function(){ + let actual = rockPaperScissors(' rock ', ' paper'); + let expected = 'Hand two wins!'; + assert.equal(actual, expected); + }); + + it('should properly handle uppercase letters', function(){ + let actual = rockPaperScissors('ROCK', 'SCISSORS'); + let expected = 'Hand one wins!'; + assert.equal(actual, expected); + }); + + it('should only take in string data types', function(){ + let actual = rockPaperScissors(4, undefined); + let expected = 'try again!'; + assert.equal(actual, expected); + }); + + it('should only take in the word strings rock, paper, and scissors', function(){ + let actual = rockPaperScissors('coffee', 'tea'); + let expected = 'try again!'; + assert.equal(actual, expected); + }); + + it('should handle empty strings and empty input', function(){ + let actual = rockPaperScissors('', ); + let expected = 'try again!'; + assert.equal(actual, expected); + }) + + }); } else { // always returns ask the user for another input