diff --git a/main.js b/main.js index 72f0f1a8..0dc224ce 100644 --- a/main.js +++ b/main.js @@ -12,13 +12,37 @@ 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 +const rockPaperScissors = (hand1, hand2) => { + let Words = ['rock', 'paper', 'scissors']; + let i = Words.indexOf(hand1.toLowerCase()); + let ii = Words.indexOf(hand2.toLowerCase()); + let SumN = i + ii; + let Outcome='Hand two wins!' + , Winner = 'Hand one wins!' + , Tie = "It's a tie!"; + if (i == ii) { + //Msg = 'Tie'; + Outcome = Tie; + } + else if (SumN == 1) { + //Msg = 'Paper covers Rock'; + if (i == 1) Outcome = Winner; + } + else if (SumN == 2) { + //Msg = 'Rock destroys Scissors'; + if (i == 0) Outcome = Winner; + } + else if (SumN == 3) { + //Msg = 'Scissors cut Paper'; + if (i == 2) Outcome = Winner; + }; + console.log(Outcome) } + + // 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 @@ -60,3 +84,6 @@ if (typeof describe === 'function') { getPrompt(); } + + +//assert.equal(rockPaperScissors('rock', 'rock'), "It's a tie!") diff --git a/test.js b/test.js new file mode 100644 index 00000000..764087c5 --- /dev/null +++ b/test.js @@ -0,0 +1,39 @@ +let PlayGame = (hand1,hand2) => { + let Words = ['rock', 'paper', 'scissors']; + let i = Words.indexOf(hand1.toLowerCase()); + let ii = Words.indexOf(hand2.toLowerCase()); + let SumN = i + ii; + let Outcome='Hand two wins!' + , Winner = 'Hand one wins!' + , Tie = "It's a tie!"; + + if (i == ii) { + //Msg = 'Tie'; + Outcome = Tie; + } + else if (SumN == 1) { + //Msg = 'Paper covers Rock'; + if (i == 1) Outcome = Winner; + } + else if (SumN == 2) { + //Msg = 'Rock destroys Scissors'; + if (i == 0) Outcome = Winner; + } + else if (SumN == 3) { + //Msg = 'Scissors cut Paper'; + if (i == 2) Outcome = Winner; + }; + console.log(Outcome) +}; + + +PlayGame('rock','rock'); +PlayGame('rock','paper'); +PlayGame('rock','scissors'); + +PlayGame('paper','paper'); +PlayGame('paper','scissors'); + +PlayGame('scissors','scissors'); + +