From 621bb77721e91b3e68e993ab41a3d70e28d892b6 Mon Sep 17 00:00:00 2001 From: DavidStephenss Date: Tue, 14 Jul 2020 15:37:15 -0500 Subject: [PATCH 1/3] done --- main.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 72f0f1a8..fb520dff 100644 --- a/main.js +++ b/main.js @@ -12,8 +12,58 @@ const rl = readline.createInterface({ }); // the function that will be called by the unit test below -const rockPaperScissors = (hand1, hand2) => { + +const rockPaperScissors = (firstHand, secondHand) => { + let hand1 = firstHand.toLowerCase().trim()
 + let hand2 = secondHand.toLowerCase().trim() + //detect tie + + if (hand1 === 'rock' && hand2 === 'rock') { + return "It's a tie!" + } + if ( hand1 === 'paper' && hand2 === 'paper') { + return "It's a tie!" + } + if (hand1 === 'scissors' && hand2 === 'scissors') { + return "It's a tie!" + } + + //detect win + + if (hand1 === 'paper' && hand2 === 'rock') { + return "Hand one wins!" + } + if (hand1 === 'scissors' && hand2 === 'paper') { + return "Hand one wins!" + } + if (hand1 === 'rock' && hand2 === 'scissors') { + return "Hand one wins!" + } + + if (hand1 === 'rock' && hand2 === 'paper') { + return "Hand two wins!" + } + if (hand1 === 'paper' && hand2 === 'scissors') { + return "Hand two wins!" + } + if (hand1 === 'scissors' && hand2 === 'rock') { + return "Hand two wins!" + } + // const trimAndCase = () => { + // let firstHand = hand1.toLowerCase().trim()
 + // let secondHand = hand2.toLowerCase().trim() + // } + // Cap, lower case + // if (hand1 === 'rOck' && hand2 === 'paper') { + // return "Hand two wins!" + // } + // if (hand1 === 'Paper' && hand2 === 'SCISSORS') { + // return "Hand two Wins!" + // } + // if (hand1 === 'sCiSsOrs' && hand2 === 'rock') { + // return "Hand two Wins!" + // } // Write code here // Use the unit test to see what is expected @@ -48,7 +98,7 @@ if (typeof describe === 'function') { assert.equal(rockPaperScissors('paper', 'scissors'), "Hand two wins!"); assert.equal(rockPaperScissors('rock', 'scissors'), "Hand one wins!"); }); - it('should scrub input to ensure lowercase with "trim"ed whitepace', () => { + it('should scrub input to ensure lowercase with "trim"ed whitespace', () => { assert.equal(rockPaperScissors('rOcK', ' paper '), "Hand two wins!"); assert.equal(rockPaperScissors('Paper', 'SCISSORS'), "Hand two wins!"); assert.equal(rockPaperScissors('rock ', 'sCiSsOrs'), "Hand one wins!"); From 2c3192781d561a7c7993480b7c6c723d8eba0744 Mon Sep 17 00:00:00 2001 From: DavidStephenss Date: Tue, 14 Jul 2020 16:56:14 -0500 Subject: [PATCH 2/3] yeesh --- index.html | 5 ++++- main.js | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 8f536de8..3af6f15d 100644 --- a/index.html +++ b/index.html @@ -3,13 +3,16 @@ -

Hello World!


+ + +
+ diff --git a/main.js b/main.js index fb520dff..e7c4d547 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,9 @@ // uses strict mode so strings are not coerced, variables are not hoisted, etc... 'use strict'; +let value1 = "" +let value2 = "" + // brings in the assert module for unit testing const assert = require('assert'); // brings in the readline module to access the command line @@ -13,6 +16,19 @@ const rl = readline.createInterface({ // the function that will be called by the unit test below +const storeHand = (id, value) => { +if (id == "first-hand") { + value1 = value +} else if (id == "second-hand") { + value2 = value +} +} + +const displayResults = () => { + document.getElementById(display-element).innerHTML = rockPaperScissors(value1, value2) +} + + const rockPaperScissors = (firstHand, secondHand) => { let hand1 = firstHand.toLowerCase().trim()
 From ee1e073dc75bd78fc27bb34e01bd21192871d61f Mon Sep 17 00:00:00 2001 From: DavidStephenss Date: Thu, 16 Jul 2020 11:32:57 -0500 Subject: [PATCH 3/3] newtest --- index.html | 4 ++-- main.js | 20 +++++--------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/index.html b/index.html index 3af6f15d..e14cc340 100644 --- a/index.html +++ b/index.html @@ -7,11 +7,11 @@

Hello World!


-
+
You suck
- +
diff --git a/main.js b/main.js index e7c4d547..baa26171 100644 --- a/main.js +++ b/main.js @@ -25,7 +25,7 @@ if (id == "first-hand") { } const displayResults = () => { - document.getElementById(display-element).innerHTML = rockPaperScissors(value1, value2) + document.getElementById("display-element").innerHTML = rockPaperScissors(value1, value2) } @@ -66,20 +66,6 @@ const rockPaperScissors = (firstHand, secondHand) => { if (hand1 === 'scissors' && hand2 === 'rock') { return "Hand two wins!" } - // const trimAndCase = () => { - // let firstHand = hand1.toLowerCase().trim()
 - // let secondHand = hand2.toLowerCase().trim() - // } - // Cap, lower case - // if (hand1 === 'rOck' && hand2 === 'paper') { - // return "Hand two wins!" - // } - // if (hand1 === 'Paper' && hand2 === 'SCISSORS') { - // return "Hand two Wins!" - // } - // if (hand1 === 'sCiSsOrs' && hand2 === 'rock') { - // return "Hand two Wins!" - // } // Write code here // Use the unit test to see what is expected @@ -119,6 +105,10 @@ if (typeof describe === 'function') { assert.equal(rockPaperScissors('Paper', 'SCISSORS'), "Hand two wins!"); assert.equal(rockPaperScissors('rock ', 'sCiSsOrs'), "Hand one wins!"); }); + it('enter input before pressing enter', () => { + assert.equal(rockPaperScissors( undefined, 'paper'), "Please enter valid hand"); + assert.equal(rockPaperScissors('Paper', undefined), "Please enter valid hand"); + }); }); } else {