From 286242e236d6705272e4623a88008d7096cbe980 Mon Sep 17 00:00:00 2001 From: nlewis989 <71626506+nlewis989@users.noreply.github.com> Date: Sun, 19 Sep 2021 21:22:05 -0500 Subject: [PATCH 1/2] Final edit --- main.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 72f0f1a8..6829d70a 100644 --- a/main.js +++ b/main.js @@ -1,4 +1,4 @@ -// uses strict mode so strings are not coerced, variables are not hoisted, etc... +// uses strict mode so strings are not coerced, variables are not hoisted, etc... 'use strict'; // brings in the assert module for unit testing @@ -11,21 +11,53 @@ const rl = readline.createInterface({ output: process.stdout }); +/*the function returns the following +*if hand1 is the winning hand return "hand one wins!" +*if hand2 is the winning hand return "hand two wins!" +*if it is a tie return "it's a tie!" +*/ + // the function that will be called by the unit test below const rockPaperScissors = (hand1, hand2) => { // Write code here // Use the unit test to see what is expected + // we set a modification here because the program is case sensitive and you want to satisfy the if statements + hand1 = hand1.trim().toLowerCase(); + hand2 = hand2.trim().toLowerCase(); + + if (hand1 === hand2) { + return "It's a tie!" + } + if (hand1 === "rock" && hand2 === "paper"){ + return "Hand two wins!" + } + if (hand1 === "rock" && hand2 === "scissors"){ + return "Hand one wins!" + } + if (hand1 === "paper" && hand2 === "scissors"){ + return "Hand two wins!" + } + if (hand1 === "paper" && hand2 === "rock"){ + return "Hand one wins!" + } + if (hand1 === "scissors" && hand2 === "rock"){ + return "Hand two wins!" + } + if (hand1 === "scissors" && hand2 === "paper"){ + return "Hand one 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 function getPrompt() { rl.question('hand1: ', (answer1) => { rl.question('hand2: ', (answer2) => { - console.log( rockPaperScissors(answer1, answer2) ); + console.log(rockPaperScissors(answer1, answer2)); getPrompt(); }); }); @@ -54,9 +86,25 @@ if (typeof describe === 'function') { assert.equal(rockPaperScissors('rock ', 'sCiSsOrs'), "Hand one wins!"); }); }); + } else { // always returns ask the user for another input getPrompt(); - } + + +/* Code Plan: +1. User1 input of rock, paper, or scissors. +2. User2 input of rock, paper, or scissors. +3. Compare User1 input to User2 input. +4. If User1 input is 'rock' and User2 input is 'scissor', User1 wins. +5. If User1 input is 'rock' and User2 input is 'paper', User2 wins. +6. If User1 input is 'rock' and User2 input is 'rock', it's a tie. +7. If User1 input is 'paper' and User2 input is 'rock', User1 wins. +8. If User1 input is 'paper' and User2 input is 'scissors', User2 wins. +9. If User1 input is 'paper' and User2 input is 'paper', it's a tie. +10. If User1 input is 'scissors' and User2 input is 'paper', User1 wins. +11. If User1 input is 'scissors' and User2 input is 'rock', User2 wins. +12. If User1 input is 'scissors' and User2 input is 'scissors', it's a tie. +*/ \ No newline at end of file From 47adad9cb926679f79ecf114912eac6ad369e07c Mon Sep 17 00:00:00 2001 From: nlewis989 <71626506+nlewis989@users.noreply.github.com> Date: Mon, 4 Oct 2021 15:47:03 -0500 Subject: [PATCH 2/2] final edit --- main.js | 124 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 76 insertions(+), 48 deletions(-) diff --git a/main.js b/main.js index 6829d70a..7b5c34c8 100644 --- a/main.js +++ b/main.js @@ -11,45 +11,59 @@ const rl = readline.createInterface({ output: process.stdout }); -/*the function returns the following -*if hand1 is the winning hand return "hand one wins!" -*if hand2 is the winning hand return "hand two wins!" -*if it is a tie return "it's a tie!" -*/ - // the function that will be called by the unit test below const rockPaperScissors = (hand1, hand2) => { - // Write code here - // Use the unit test to see what is expected - - // we set a modification here because the program is case sensitive and you want to satisfy the if statements - hand1 = hand1.trim().toLowerCase(); - hand2 = hand2.trim().toLowerCase(); + hand1 = hand1.toLowerCase().trim(); + console.log('hand1',hand1); + hand2 = hand2.toLowerCase().trim(); + console.log("hand 2", hand2); - if (hand1 === hand2) { - return "It's a tie!" - } - if (hand1 === "rock" && hand2 === "paper"){ - return "Hand two wins!" - } - if (hand1 === "rock" && hand2 === "scissors"){ - return "Hand one wins!" + if(hand1== 'saw'|| hand1 =='hammer'|| hand2=='saw'||hand2=='hammer'){ + return 'no tools allowed' + }; + if(hand1== 'casa'|| hand1 =='la manzana es muy rico'|| hand2=='casa'||hand2=='la manzana es muy rico'){ + return 'sorry no spanish' + }; + if(hand1== 'pencil'|| hand1 =='pen'|| hand2=='pencil'||hand2=='pen'){ + return 'sorry, needs to be rock,paper, or scissors' } - if (hand1 === "paper" && hand2 === "scissors"){ - return "Hand two wins!" + if(hand1== 'Trump'|| hand1 =='Biden'|| hand2=='Trump'||hand2=='Biden'){ + return 'bad input' } - if (hand1 === "paper" && hand2 === "rock"){ - return "Hand one wins!" + + + + + + + if(hand1 !== 'rock'&&hand1 !=="scissors"&&hand1!=='paper' ){ + return 'bad input'; + } - if (hand1 === "scissors" && hand2 === "rock"){ - return "Hand two wins!" + if(hand2 !== 'rock'&&hand2 !=="scissors"&&hand2!=='paper' ){ + return 'bad input'; + } - if (hand1 === "scissors" && hand2 === "paper"){ - return "Hand one wins!" + if(hand1 === hand2){ + return "It's a tie!"; + } else if(hand1 === 'rock' && hand2 === 'paper') { + return "Hand two wins!"; + } else if(hand1 === 'paper' && hand2 === 'scissors') { + return "Hand two wins!"; + } else if(hand1 === 'scissors' && hand2 === 'rock') { + return "Hand two wins!"; + } else if(hand1 === 'paper' && hand2 === 'rock') { + return "Hand one wins!"; + } else if(hand1 === 'scissors' && hand2 === 'paper') { + return "Hand one wins!"; + } else if(hand1 === 'rock' && hand2 === 'scissors') { + return "Hand one wins!"; } -} + // Write code here + // Use the unit test to see what is expected +} // the first function called in the program to get an input from the user // to run the function use the command: node main.js @@ -57,18 +71,18 @@ const rockPaperScissors = (hand1, hand2) => { function getPrompt() { rl.question('hand1: ', (answer1) => { rl.question('hand2: ', (answer2) => { - console.log(rockPaperScissors(answer1, answer2)); + console.log( rockPaperScissors(answer1, answer2) ); getPrompt(); }); }); } // Unit Tests -// You use them run the command: npm test main.js +// to use them run the command: npm test main.js // to close them ctrl + C if (typeof describe === 'function') { - // most are notes for human eyes to read, but essentially passes in inputs then compares if the function you built return the expected output. + // most are notes for human eyes to read, but essentially passes in inputs then compares if the function you built returns the expected output. describe('#rockPaperScissors()', () => { it('should detect a tie', () => { assert.equal(rockPaperScissors('rock', 'rock'), "It's a tie!"); @@ -86,25 +100,39 @@ if (typeof describe === 'function') { assert.equal(rockPaperScissors('rock ', 'sCiSsOrs'), "Hand one wins!"); }); }); + // additional tests! + describe('RPS unit test assignment', ()=>{ + + it('should handle bad input', ()=>{ + let actual = rockPaperScissors('poop','spider'); + let expected = 'bad input'; + assert.equal(actual, expected); + }) + it('shouldnt handle tools', ()=>{ + let actual = rockPaperScissors('saw','hammer'); + let expected = 'no tools allowed'; + assert.equal(actual, expected); + }) + it('shouldnt handle spanish words', ()=>{ + let actual = rockPaperScissors("casa",'la manzana es muy rico'); + let expected = "sorry no spanish"; + assert.equal(actual, expected); + }) + it('synonyms',()=>{ + let actual = rockPaperScissors('pencil','pen'); + let expected = 'sorry, needs to be rock, paper, or scissors'; + assert.equal(actual, expected); + }) + it('politics',()=>{ + let actual = rockPaperScissors('Trump',"Biden"); + let expected = "bad input"; + assert.equal(actual,expected); + }) + }) } else { // always returns ask the user for another input getPrompt(); -} - -/* Code Plan: -1. User1 input of rock, paper, or scissors. -2. User2 input of rock, paper, or scissors. -3. Compare User1 input to User2 input. -4. If User1 input is 'rock' and User2 input is 'scissor', User1 wins. -5. If User1 input is 'rock' and User2 input is 'paper', User2 wins. -6. If User1 input is 'rock' and User2 input is 'rock', it's a tie. -7. If User1 input is 'paper' and User2 input is 'rock', User1 wins. -8. If User1 input is 'paper' and User2 input is 'scissors', User2 wins. -9. If User1 input is 'paper' and User2 input is 'paper', it's a tie. -10. If User1 input is 'scissors' and User2 input is 'paper', User1 wins. -11. If User1 input is 'scissors' and User2 input is 'rock', User2 wins. -12. If User1 input is 'scissors' and User2 input is 'scissors', it's a tie. -*/ \ No newline at end of file +} \ No newline at end of file