From 16314ae7da5c1a1e7ca95b24366f01d48992cf31 Mon Sep 17 00:00:00 2001 From: David Castillo Date: Thu, 16 Sep 2021 14:35:41 -0500 Subject: [PATCH 1/2] Initial Commit --- index.html | 6 +----- main.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 8f536de8..38d586bf 100644 --- a/index.html +++ b/index.html @@ -6,10 +6,6 @@ -

Hello World!

-
-
- -
+ diff --git a/main.js b/main.js index e98b0914..9c263de6 100644 --- a/main.js +++ b/main.js @@ -60,3 +60,25 @@ if (typeof describe === 'function') { getPrompt(); } + + +// Heres a different way I wrote + +let PlayGame = (Player1,PLayer2) => { + let words = ['rock', 'paper', 'scissors'] + let P1 = words.indexOf(Player1.toLowerCase()) + let P2 = words.indexOf(PLayer2.toLowerCase()) + console.log('User1:' + words[P1] + ' User2:' + words[P2]) + if (P1 === P2) {console.log('Tie!')} + else if (P1 === 0 & P2 === 2) {console.log('User1 Wins')} + else if (P1 === 1 & P2 === 0) {console.log('User1 Wins')} + else if (P1 === 2 & P2 === 1) {console.log('User1 Wins')} + else if (P2 === 0 & P1 === 2) {console.log('User2 Wins')} + else if (P2 === 1 & P1 === 0) {console.log('User2 Wins')} + else if (P2 === 2 & P1 === 1) {console.log('User2 Wins')} +} + +PlayGame('rock','rock') +PlayGame('rock','scissors') + +PlayGame('paper','scissors') \ No newline at end of file From c0f7b7d95d4a4e65e15311c771a6dd474aadc633 Mon Sep 17 00:00:00 2001 From: David Castillo Date: Thu, 16 Sep 2021 15:24:29 -0500 Subject: [PATCH 2/2] Finished Homework --- main.js | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/main.js b/main.js index 9c263de6..2f0de9da 100644 --- a/main.js +++ b/main.js @@ -13,10 +13,16 @@ const rl = readline.createInterface({ // 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 - + let words = ['rock', 'paper', 'scissors'] + let User1 = words.indexOf(hand1.trim().toLowerCase()) + let User2 = words.indexOf(hand2.trim().toLowerCase()) +if (User1 === User2) {return "It's a tie!"} +else if (User1 === 0 & User2 === 2) {return "Hand one wins!"} +else if (User1 === 1 & User2 === 0) {return "Hand one wins!"} +else if (User1 === 2 & User2 === 1) {return "Hand one wins!"} +else if (User2 === 0 & User1 === 2) {return "Hand two wins!"} +else if (User2 === 1 & User1 === 0) {return "Hand two wins!"} +else if (User2 === 2 & User1 === 1) {return "Hand two wins!"} } // the first function called in the program to get an input from the user @@ -62,23 +68,22 @@ if (typeof describe === 'function') { } -// Heres a different way I wrote -let PlayGame = (Player1,PLayer2) => { - let words = ['rock', 'paper', 'scissors'] - let P1 = words.indexOf(Player1.toLowerCase()) - let P2 = words.indexOf(PLayer2.toLowerCase()) - console.log('User1:' + words[P1] + ' User2:' + words[P2]) - if (P1 === P2) {console.log('Tie!')} - else if (P1 === 0 & P2 === 2) {console.log('User1 Wins')} - else if (P1 === 1 & P2 === 0) {console.log('User1 Wins')} - else if (P1 === 2 & P2 === 1) {console.log('User1 Wins')} - else if (P2 === 0 & P1 === 2) {console.log('User2 Wins')} - else if (P2 === 1 & P1 === 0) {console.log('User2 Wins')} - else if (P2 === 2 & P1 === 1) {console.log('User2 Wins')} -} +// let PlayGame = (Player1,PLayer2) => { +// let words = ['rock', 'paper', 'scissors'] +// let P1 = words.indexOf(Player1.toLowerCase()) +// let P2 = words.indexOf(PLayer2.toLowerCase()) +// console.log('User1:' + words[P1] + ' User2:' + words[P2]) + // if (P1 === P2) {console.log('Tie!')} + // else if (P1 === 0 & P2 === 2) {console.log('User1 Wins')} + // else if (P1 === 1 & P2 === 0) {console.log('User1 Wins')} + // else if (P1 === 2 & P2 === 1) {console.log('User1 Wins')} + // else if (P2 === 0 & P1 === 2) {console.log('User2 Wins')} + // else if (P2 === 1 & P1 === 0) {console.log('User2 Wins')} + // else if (P2 === 2 & P1 === 1) {console.log('User2 Wins')} +// } -PlayGame('rock','rock') -PlayGame('rock','scissors') +// PlayGame('rock','rock') +// PlayGame('rock','scissors') -PlayGame('paper','scissors') \ No newline at end of file +// PlayGame('paper','scissors') \ No newline at end of file