Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>ROCK PAPER SCISSORS THE GAME</title>
- </head>
- <body>
- <button onClick='choose("rock")'>Rock</button>
- <button onClick='choose("paper")'>Paper</button>
- <button onClick='choose("scissors")'>Scissors</button><br>
- <button onClick='compare(userschoice, computerschoice)'>Go!</button>
- <p id="result"></p>
- <script>
- var userschoice;
- var choose = function(choice)
- {
- userschoice = choice;
- }
- var computerschoice = Math.random();
- if (0 < computerschoice < 0.30)
- {
- computerschoice = "rock";
- }
- else if (0.31 < computerschoice < 0.60)
- {
- computerschoice = "paper";
- }
- else
- {
- computerschoice = "scissors";
- }
- var compare = function(firstChoice,secondChoice)
- {
- if (firstChoice === secondChoice)
- {
- document.getElementById("result").innerHTML = ("It's a tie!")
- }
- else if (firstChoice === "rock")
- {
- if (secondChoice === "scissors")
- {
- document.getElementById("result").innerHTML = ("You win!")
- }
- else
- {
- document.getElementById("result").innerHTML = ("You lost.")
- }
- }
- else if (firstChoice === "paper")
- {
- if (secondChoice === "rock")
- {
- document.getElementById("result").innerHTML = ("You win!")
- }
- else
- {
- document.getElementById("result").innerHTML = ("You lost.")
- }
- }
- else if (firstChoice === "scissors")
- {
- if (secondChoice === "paper")
- {
- document.getElementById("result").innerHTML = ("You win!")
- }
- else
- {
- document.getElementById("result").innerHTML = ("You lost.")
- }
- }
- }
- compare(userschoice, computerschoice)
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement