From 9bf8daf44e83011364ccefc990368bfb5319ae01 Mon Sep 17 00:00:00 2001 From: TEldridge Date: Tue, 14 Jul 2020 15:28:00 -0500 Subject: [PATCH 1/3] fixed for three passing --- main.js | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 72f0f1a8..e935280d 100644 --- a/main.js +++ b/main.js @@ -12,7 +12,45 @@ 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() + + // 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!" + // } + + if (hand1 === hand2){ + return "It's a tie!" + } + + 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!" +} + +if (hand1 === 'rock' && hand2 === 'scissors'){ + return "Hand one wins!" +} +if (hand1 === 'paper' && hand2 === 'rock'){ + return "Hand one wins!" +} +if (hand1 === 'scissors' && hand2 === 'paper'){ + return "Hand two wins!" +} + // Write code here // Use the unit test to see what is expected @@ -48,7 +86,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 9a26f84f233e7b53c8307900cfef7d683c8e76e3 Mon Sep 17 00:00:00 2001 From: TEldridge Date: Thu, 16 Jul 2020 11:17:43 -0500 Subject: [PATCH 2/3] made RPS work --- index.html | 32 +++++++++++++++++++------------- main.js | 25 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/index.html b/index.html index 8f536de8..f2c6a10e 100644 --- a/index.html +++ b/index.html @@ -1,15 +1,21 @@ - - - - - - -

Hello World!

-
-
- -
- - + + + + + + + + +

Hello World!

+
+
+ + + +
+ + + + \ No newline at end of file diff --git a/main.js b/main.js index e935280d..d69c224d 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 @@ -11,6 +14,28 @@ const rl = readline.createInterface({ output: process.stdout }); +//1 create two inputs +//2 create a function that when inputs are typed in is called and saves inputs to two different global variables +//3 create a button +//4 create a function, that when button is clicked, displays the results of RPS function + + +const storeHands = (value, id) => { + + if ( id == "first-hand"){ + value1 = value + } else if (id == "second-hand"){ + value2 = value + } + +} + +const displayResults = () => { + + document.getElementById("Rdisplay-element").innerHTML = rockPaperScissors(value1, value2) + +} + // the function that will be called by the unit test below const rockPaperScissors = (firstHand, secondHand) => { From 80b96cd234c789b8c577388189633a3634dbe11b Mon Sep 17 00:00:00 2001 From: TEldridge Date: Thu, 16 Jul 2020 11:32:43 -0500 Subject: [PATCH 3/3] added unit measure test --- main.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main.js b/main.js index d69c224d..918f7c9c 100644 --- a/main.js +++ b/main.js @@ -116,6 +116,11 @@ if (typeof describe === 'function') { assert.equal(rockPaperScissors('Paper', 'SCISSORS'), "Hand two wins!"); assert.equal(rockPaperScissors('rock ', 'sCiSsOrs'), "Hand one wins!"); }); + it('should test for input before asking for next hand', () => { + assert.equal(rockPaperScissors(undefined, "paper"), "Dont be dumb make a choice"); + assert.equal(rockPaperScissors('paper', undefined), "Dont be dumb make a choice"); + + }); }); } else {