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
13 changes: 11 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@
<head>
<meta charset="utf-8">
<title></title>
<script src="main.js"></script>
</head>
<body>
<h1>Hello World!</h1>
<hr/>
<div id="display-element"></div>
<button onclick="displayDate()">Click Me</button>


<button onclick="displayResults()">Click Me</button>

<label for="value1">Hand 1</label>
<input type="text" id="first-hand" name="value1" onkeyup="storeHand(this.id, this.value)"></input>
<label for="value2">Hand 2</label>
<input type="text" id="second-hand" name="value2" onkeyup="storeHand(this.id, this.value)"></input>


<script src="main.js"></script>
<hr/>
</body>
</html>
70 changes: 67 additions & 3 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,10 +15,67 @@ 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



// create two inputs
// create a function that when inputs are typed in is called and save inputs to two different global variables
// create a button
// create a function, that when button is clicked, displays the results of rpsFunction



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

}

const displayResults = (value1, value2) => {
if (value1 && value2) {
document.getElementById("display-element").innerHTML = rockPaperScissors(value1, value2)
} else {
return document.getElementById("display-element").innerHTML = "nah fam"
}
}



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

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!"
}
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!"
}
if (hand1 === 'paper' && hand2 === 'rock') {
return "Hand one wins!"
}
if (hand1 === 'rock' && hand2 === 'scissors') {
return "Hand one wins!"
}
if (hand1 === 'scissors' && hand2 === 'paper') {
return "Hand one wins!"
}

}

Expand Down Expand Up @@ -53,6 +113,10 @@ if (typeof describe === 'function') {
assert.equal(rockPaperScissors('Paper', 'SCISSORS'), "Hand two wins!");
assert.equal(rockPaperScissors('rock ', 'sCiSsOrs'), "Hand one wins!");
});
it('should test for input before next turn', () => {
assert.equal(rockPaperScissors(undefined, 'paper'), "Hand two wins! but only because hand1 belongs to an idiot who can't follow instructions");
assert.equal(rockPaperScissors('Paper', undefined), "Hand one wins! because hand2 doesn't wanna play apparently.");
});
});
} else {

Expand Down