About
Explore
Events & Classes
Support Us
Join
Sign In
Coding with Rumaysa
View Project Page
Run
Fullscreen
Rock Paper Scissors!
HTML
CSS
JS
<!DOCTYPE HTML> <html> <head> <title>Page Title</title> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1.0,shrink-to-fit=no,width=device-width"> </head> <body> <center> <h1>Rock Paper Scissors!</h1> <h3 id="prompt">Pick rock, paper or scissors</h3> </center> <div id="options" class="row"> <div id="rock" onclick="selectAction('r')">👊</div> <div id="paper" onclick="selectAction('p')">✋</div> <div id="scissors" onclick="selectAction('s')">✌</div> </div> <div id="results"> <div class="row"> <div> <h4>YOU</h4> <div id="your_choice" class="selected">✌</div> </div> <div> <h4>COMPUTER</h4> <div id="computer_choice" class="selected">✌</div> </div> </div> <center> <div class="result_msg" id="win">You win! :D</div> <div class="result_msg" id="draw">It's a draw! :|</div> <div class="result_msg" id="loss">You lost! :(</div> </center> </div> </body> </html>
@import url('https://fonts.googleapis.com/css2?family=RocknRoll+One&display=swap'); * { font-family: RocknRoll One; font-weight: bold; } body { background-color: #78e6ff; } .row { display: flex; flex-wrap: wrap; align-items: center; text-align: center; justify-content: center; } #options *, #results div.selected { font-size: 80px; } #options div, #results div.selected { background-color: white; border-radius: 50%; margin: 10px; border: 5px black solid; } #results, .result_msg { display: none; }
computerChoice = Math.floor(Math.random() * 3); yourChoice = ""; prompt = document.getElementById("prompt"); rock = document.getElementById("rock"); paper = document.getElementById("paper"); scissors = document.getElementById("scissors"); results = document.getElementById("results"); your_choice = document.getElementById("your_choice"); computer_choice = document.getElementById("computer_choice"); win = document.getElementById("win"); draw = document.getElementById("draw"); loss = document.getElementById("loss"); function selectAction(action) { yourChoice = action; if(computerChoice == 0) { computerChoice = "r"; } else if(computerChoice == 1) { computerChoice = "p"; } else if(computerChoice == 2) { computerChoice = "s"; } setSelections(); } function setSelections() { if(yourChoice == "r") { your_choice.innerHTML = "👊"; } else if(yourChoice == "p") { your_choice.innerHTML = "✋"; } else { your_choice.innerHTML = "✌"; } if(computerChoice == "r") { computer_choice.innerHTML = "👊"; } else if(computerChoice == "p") { computer_choice.innerHTML = "✋"; } else { computer_choice.innerHTML = "✌"; } determineWinOrLoss(); } function determineWinOrLoss() { prompt.style.display = "none"; rock.style.display = "none"; paper.style.display = "none"; scissors.style.display = "none"; results.style.display = "block"; if((yourChoice == "r" && computerChoice == "r") || (yourChoice == "p" && computerChoice == "p") || (yourChoice == "s" && computerChoice == "s")) { draw.style.display = "block"; } else if((yourChoice == "r" && computerChoice == "s") || (yourChoice == "s" && computerChoice == "p") || (yourChoice == "p" && computerChoice == "r")) { win.style.display = "block"; } else if((yourChoice == "s" && computerChoice == "r") || (yourChoice == "p" && computerChoice == "s") || (yourChoice == "r" && computerChoice == "p")) { loss.style.display = "block"; } }