Toggle navigation
Bootsnipp
Bootstrap
For
CSS Frameworks
Bootstrap
Foundation
Semantic UI
Materialize
Pure
Bulma
References
CSS Reference
Tools
Community
Page Builder
Form Builder
Button Builder
Icon Search
Dan's Tools
Diff / Merge
Color Picker
Keyword Tool
Web Fonts
.htaccess Generator
Favicon Generator
Site Speed Test
Snippets
Featured
Tags
By Bootstrap Version
4.1.1
4.0.0
3.3.0
3.2.0
3.1.0
3.0.3
3.0.1
3.0.0
2.3.2
Register
Login
"Rock Paper Scissors Game"
Bootstrap 4.1.1 Snippet by
mayurkarthik
4.1.1
Preview
HTML
CSS
JS
View Full Screen
Fork
Fork this
26
 
0 Fav
Post to Facebook
Tweet this
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <!DOCTYPE html> <html lang="en"> <body> <h1>Rock Paper Scissors</h1> <div class="Container"> <button onclick="playGame('rock')">Rock</button> <button onclick="playGame('paper')">Paper</button> <button onclick="playGame('scissors')">Scissors</button> </div> <p id="score-text"></p> <div class="Container"> <button onclick="resetScore()">Reset Score</button> </div> </body> </html>
body { font-family: 'Times New Roman', serif; background-color: rgb(51, 35, 50); } button { background-color: transparent; color: white; border: 2px solid white; border-radius: 14px; height: 50px; width: 75px; } hr { background-color: red; border: none; height: px; } h1 { color: white; margin-left: 770px; } #score-text { color: white; margin-left: 825px; } .Container { margin-left: 825px; }
// RPS Game Code Starts let score = JSON.parse(localStorage.getItem('score')) || { wins: 0, losses: 0, ties: 0 }; function getComputerMove() { let randomNumber = Math.random(); if (randomNumber < 1 / 3) { return 'rock'; } else if (randomNumber < 2 / 3) { return 'paper'; } else { return 'scissors'; } } function playGame(playerMove) { let computerMove = getComputerMove(); let result = ''; if (playerMove === computerMove) { result = 'Tie.'; score.ties++; } else if ( (playerMove === 'rock' && computerMove === 'scissors') || (playerMove === 'paper' && computerMove === 'rock') || (playerMove === 'scissors' && computerMove === 'paper') ) { result = 'You won.'; score.wins++; } else { result = 'You lose.'; score.losses++; } localStorage.setItem('score', JSON.stringify(score)); updateScore(); document.getElementById('score-text').innerText = `${result} You ${playerMove} - Computer ${computerMove} Wins: ${score.wins}, Losses: ${score.losses}, Ties: ${score.ties}`; } function updateScore() { document.getElementById('score-text').innerText = `Wins: ${score.wins}, Losses: ${score.losses}, Ties: ${score.ties}`; } function resetScore() { score.wins = 0; score.losses = 0; score.ties = 0; localStorage.setItem('score', JSON.stringify(score)); updateScore(); } // updateScore(); // RPS Game Ends
Related:
See More
Free Template
Black Dashboard React
Questions / Comments:
Post
Posting Guidelines
Formatting
- Now
×
Close
Donate
BTC: 12JxYMYi6Vt3mx3hcmP3B2oyFiCSF3FhYT
ETH: 0xCD715b2E3549c54A40e6ecAaFeB82138148a6c76