diff --git a/main.js b/main.js index e98b0914..b07700f4 100644 --- a/main.js +++ b/main.js @@ -1,7 +1,7 @@ // uses strict mode so strings are not coerced, variables are not hoisted, etc... 'use strict'; -// brings in the assert module for unit testing +// brings in to assert module for unit testing const assert = require('assert'); // brings in the readline module to access the command line const readline = require('readline'); @@ -11,12 +11,23 @@ const rl = readline.createInterface({ output: process.stdout }); + // the function that will be called by the unit test below -const rockPaperScissors = (hand1, hand2) => { +const rockPaperScissors = (answer1, answer2) => { + let userOne = answer1.trim().toLowerCase() + let userTwo = answer2.trim().toLowerCase() + + if (userOne === userTwo) {return "It's a tie!"} + if (userOne === 'rock' && userTwo === 'paper'){return "Hand two wins!"} + if (userOne === 'paper' && userTwo === 'scissors'){return "Hand two wins!"} + if (userOne === 'scissors' && userTwo === 'rock'){return "Hand two wins!"} + if (userOne === 'paper' && userTwo === 'rock'){return "Hand one wins!"} + if (userOne === 'scissors' && userTwo === 'paper'){return "Hand one wins!"} + if (userOne === 'rock' && userTwo === 'scissors'){return "Hand one wins!"} + // Write code here // Use the unit test to see what is expected - } // the first function called in the program to get an input from the user @@ -25,7 +36,7 @@ const rockPaperScissors = (hand1, hand2) => { function getPrompt() { rl.question('hand1: ', (answer1) => { rl.question('hand2: ', (answer2) => { - console.log( rockPaperScissors(answer1, answer2) ); + console.log(rockPaperScissors(answer1, answer2)); getPrompt(); }); }); @@ -36,7 +47,7 @@ function getPrompt() { // to close them ctrl + C if (typeof describe === 'function') { - // most are notes for human eyes to read, but essentially passes in inputs then compares if the function you built returns the expected output. + // most are notes for human eyes to read, but essentially passes in inputs then compares if the function you built returns the expected output. describe('#rockPaperScissors()', () => { it('should detect a tie', () => { assert.equal(rockPaperScissors('rock', 'rock'), "It's a tie!"); @@ -48,7 +59,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!"); @@ -56,7 +67,7 @@ if (typeof describe === 'function') { }); } else { - // always returns ask the user for another input + // always returns ask the user for another input getPrompt(); }