Created
November 30, 2017 02:35
-
-
Save xavi-/b9fea21e33fe4afca73f1b9085f7f985 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=b9fea21e33fe4afca73f1b9085f7f985
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Rock Paper Scissors Checker</title> | |
</head> | |
<body> | |
<p> | |
Player1: <input id="player-1"> | |
</p> | |
<p> | |
Player2: <input id="player-2"> | |
</p> | |
<p> | |
<button>Who's the winner?</button> | |
</p> | |
<p id="winner">No one yet!</p> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"enabledLibraries":["jquery"],"hiddenUIComponents":["editor.css"]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This clicker handler checks the values of the inputs, | |
// determines the winnder (using if-statements), and shows | |
// the winner on the page. | |
$("button").click(function(){ | |
// get the value of player choices | |
var player1 = $("#player-1").val(); | |
var player2 = $("#player-2").val(); | |
var winnerText = "not sure yet"; | |
// determine who won | |
// to do: fill in the other possibilities | |
if(player1 === "rock" && player2 === "rock") { | |
winnerText = "It's a tie!"; | |
} /* else if (...) { | |
Add conditionals for all the other possibilities | |
} */ | |
// show the winner text on the page | |
$("#winner").text(winnerText); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment