From a7b8ce71a67ccb9b9d23f6143e3b7f3ee7067133 Mon Sep 17 00:00:00 2001 From: monica-suarez Date: Wed, 29 Apr 2020 21:01:26 -0500 Subject: [PATCH 1/4] before fixing errors --- .vscode/settings.json | 3 +++ main.js | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..6f3a2913 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5501 +} \ No newline at end of file diff --git a/main.js b/main.js index 72f0f1a8..6eecb850 100644 --- a/main.js +++ b/main.js @@ -12,12 +12,20 @@ const rl = readline.createInterface({ }); // the function that will be called by the unit test below +let scissors = "scissors" +let paper = "paper" +let rock = "rock" const rockPaperScissors = (hand1, hand2) => { - - // Write code here - // Use the unit test to see what is expected - -} + if(hand1 == hand2){ + return "It's a tie!"; + } + if(hand1 == rock && hand2 == scissors ||hand1 == paper && hand2 == rock || hand1 == scissors && hand2 == paper){ + return "Hand one wins!"; + } + if(hand2 == rock && hand1 == scissors ||hand2 == paper && hand1 == rock || hand2 == scissors && hand1 == paper){ + 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 From ab8ca059ebb1e4e99020b7544ba0259e7c5984c4 Mon Sep 17 00:00:00 2001 From: monica-suarez Date: Wed, 29 Apr 2020 21:05:11 -0500 Subject: [PATCH 2/4] assgn done --- main.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.js b/main.js index 6eecb850..ba599e68 100644 --- a/main.js +++ b/main.js @@ -16,6 +16,10 @@ let scissors = "scissors" let paper = "paper" let rock = "rock" const rockPaperScissors = (hand1, hand2) => { + hand1 = hand1.toLowerCase(); + hand2 = hand2.toLowerCase(); + hand1 = hand1.trim(); + hand2 = hand2.trim(); if(hand1 == hand2){ return "It's a tie!"; } From fc54e9a4a8d8736976a6d7388d78b4b90d9dc771 Mon Sep 17 00:00:00 2001 From: monica-suarez Date: Sun, 3 May 2020 14:11:05 -0500 Subject: [PATCH 3/4] added error --- main.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.js b/main.js index ba599e68..b8c142da 100644 --- a/main.js +++ b/main.js @@ -29,6 +29,9 @@ const rockPaperScissors = (hand1, hand2) => { if(hand2 == rock && hand1 == scissors ||hand2 == paper && hand1 == rock || hand2 == scissors && hand1 == paper){ return "Hand two wins!"; } + else{ + return "Take that weapon elsewhere! Approved weapons only!" + } }; // the first function called in the program to get an input from the user From d6afa89cffd975376f4de3df46c261055e4cd53f Mon Sep 17 00:00:00 2001 From: monica-suarez Date: Wed, 6 May 2020 20:05:47 -0500 Subject: [PATCH 4/4] save this bad boy --- main.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index b8c142da..7d7b25ea 100644 --- a/main.js +++ b/main.js @@ -20,7 +20,7 @@ const rockPaperScissors = (hand1, hand2) => { hand2 = hand2.toLowerCase(); hand1 = hand1.trim(); hand2 = hand2.trim(); - if(hand1 == hand2){ + if(hand1 == hand2 && hand1 != ""){ return "It's a tie!"; } if(hand1 == rock && hand2 == scissors ||hand1 == paper && hand2 == rock || hand1 == scissors && hand2 == paper){ @@ -29,6 +29,9 @@ const rockPaperScissors = (hand1, hand2) => { if(hand2 == rock && hand1 == scissors ||hand2 == paper && hand1 == rock || hand2 == scissors && hand1 == paper){ return "Hand two wins!"; } + if(hand1 == "" || hand2 == ""){ + return "Try this again. You didn't input anything." + } else{ return "Take that weapon elsewhere! Approved weapons only!" } @@ -68,6 +71,9 @@ if (typeof describe === 'function') { assert.equal(rockPaperScissors('Paper', 'SCISSORS'), "Hand two wins!"); assert.equal(rockPaperScissors('rock ', 'sCiSsOrs'), "Hand one wins!"); }); + it('should detect empty string in input', () =>{ + assert.equal(rockPaperScissors('', ''), "Try this again. You didn't input anything."); + }); }); } else {