Skip to content

Instantly share code, notes, and snippets.

@xavi-
Created November 30, 2017 02:35
Show Gist options
  • Save xavi-/b9fea21e33fe4afca73f1b9085f7f985 to your computer and use it in GitHub Desktop.
Save xavi-/b9fea21e33fe4afca73f1b9085f7f985 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=b9fea21e33fe4afca73f1b9085f7f985
<!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>
{"enabledLibraries":["jquery"],"hiddenUIComponents":["editor.css"]}
// 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