Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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
Expand All @@ -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();
});
});
Expand All @@ -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!");
Expand All @@ -48,15 +59,15 @@ 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!");
});
});
} else {

// always returns ask the user for another input
// always returns ask the user for another input
getPrompt();

}