Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
<head>
<meta charset="utf-8">
<title></title>
<script src="main.js"></script>
</head>
<body>
<h1>Hello World!</h1>
<hr/>
<div id="display-element"></div>
<div id="display-element">You suck</div>
<button onclick="displayDate()">Click Me</button>
<input type="text" id="first-hand" name="first-hand" value="" onkeyup="storeHand(this.id, this.value)">
<input type="text" id="second-hand" name="second-hand" value="" onkeyup="storeHand(this.id, this.value)">
<button onclick="displayResults()">Results</button>
<hr/>
<script src="main.js"></script>
</body>
</html>
60 changes: 58 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// uses strict mode so strings are not coerced, variables are not hoisted, etc...
'use strict';

let value1 = ""
let value2 = ""

// brings in the assert module for unit testing
const assert = require('assert');
// brings in the readline module to access the command line
Expand All @@ -12,8 +15,57 @@ const rl = readline.createInterface({
});

// the function that will be called by the unit test below
const rockPaperScissors = (hand1, hand2) => {

const storeHand = (id, value) => {
if (id == "first-hand") {
value1 = value
} else if (id == "second-hand") {
value2 = value
}
}

const displayResults = () => {
document.getElementById("display-element").innerHTML = rockPaperScissors(value1, value2)
}



const rockPaperScissors = (firstHand, secondHand) => {
let hand1 = firstHand.toLowerCase().trim()

let hand2 = secondHand.toLowerCase().trim()
//detect tie

if (hand1 === 'rock' && hand2 === 'rock') {
return "It's a tie!"
}
if ( hand1 === 'paper' && hand2 === 'paper') {
return "It's a tie!"
}
if (hand1 === 'scissors' && hand2 === 'scissors') {
return "It's a tie!"
}

//detect win

if (hand1 === 'paper' && hand2 === 'rock') {
return "Hand one wins!"
}
if (hand1 === 'scissors' && hand2 === 'paper') {
return "Hand one wins!"
}
if (hand1 === 'rock' && hand2 === 'scissors') {
return "Hand one wins!"
}

if (hand1 === 'rock' && hand2 === 'paper') {
return "Hand two wins!"
}
if (hand1 === 'paper' && hand2 === 'scissors') {
return "Hand two wins!"
}
if (hand1 === 'scissors' && hand2 === 'rock') {
return "Hand two wins!"
}
// Write code here
// Use the unit test to see what is expected

Expand Down Expand Up @@ -48,11 +100,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!");
});
it('enter input before pressing enter', () => {
assert.equal(rockPaperScissors( undefined, 'paper'), "Please enter valid hand");
assert.equal(rockPaperScissors('Paper', undefined), "Please enter valid hand");
});
});
} else {

Expand Down