From 6530d6263222733ed40fef7c675bbe9b582310c2 Mon Sep 17 00:00:00 2001 From: Kevin Valias Date: Tue, 14 Jul 2020 15:37:54 -0500 Subject: [PATCH 1/2] final commit --- main.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 72f0f1a8..a228d103 100644 --- a/main.js +++ b/main.js @@ -5,6 +5,7 @@ const assert = require('assert'); // brings in the readline module to access the command line const readline = require('readline'); +const { strict } = require('assert'); // use the readline module to print out to the command line const rl = readline.createInterface({ input: process.stdin, @@ -12,13 +13,54 @@ 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() + + // Should come back a 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!" + } + + // Detects which hand 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!" + } + + 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!" + } + // Write code here + // Use the unit test to see what is expected } - +const trimAndCase = () => { + str.toLowerCase() + str.trim() +} // 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 @@ -31,6 +73,14 @@ function getPrompt() { }); } + + + + + + + + // Unit Tests // You use them run the command: npm test main.js // to close them ctrl + C From ddadeb9198fccd05a70ef8854989a39a68df83eb Mon Sep 17 00:00:00 2001 From: Kevin Valias Date: Thu, 16 Jul 2020 11:34:09 -0500 Subject: [PATCH 2/2] unit test --- index.html | 8 ++++++-- main.js | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 8f536de8..8aa63d8c 100644 --- a/index.html +++ b/index.html @@ -2,14 +2,18 @@ - - + Rocks Paper Scissor +

Hello World!


+ + +
+ diff --git a/main.js b/main.js index a228d103..21320093 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,12 @@ // 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 +19,25 @@ 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 = () => { + + if (value1 && Value2){ + document.getElementById("display-element").innerHTML = rockPaperScissors(value1, value2) + } else { + return document.getElementById("display-element").innerHTML = "Please Enter a Hand" + } +} + + const rockPaperScissors = (firstHand, secondHand) => {