Create A Game Using HTML
Create A Game Using HTML
@BroCodez
2 weeks ago
// ROCK PAPER SCISSORS
function playGame(playerChoice){
resultDisplay.classList.remove("greenText", "redText");
switch(result){
case "YOU WIN!":
resultDisplay.classList.add("greenText");
playerScore++;
playerScoreDisplay.textContent = playerScore;
break;
case "YOU LOSE!":
resultDisplay.classList.add("redText");
computerScore++;
computerScoreDisplay.textContent = computerScore;
break;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="choices">
<button onclick="playGame('rock')">??</button>
<button onclick="playGame('paper')">?</button>
<button onclick="playGame('scissors')">?</button>
</div>
<script src="index.js"></script>
</body>
</html>
body{
font-family: Arial, sans-serif;
font-weight: bold;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
}
h1{
font-size: 3.5rem;
color: hsl(0, 0%, 20%);
}
.choices{
margin-bottom: 30px;
}
.choices button{
font-size: 7.5rem;
min-width: 160px;
margin: 0 10px;
border-radius: 250px;
background-color: hsl(200, 100%, 50%);
cursor: pointer;
transition: background-color 0.5s ease;
}
.choices button:hover{
background-color: hsl(200, 100%, 70%);
}
#playerDisplay, #computerDisplay{
font-size: 2.5rem;
}
#resultDisplay{
font-size: 5rem;
margin: 30px 0;
}
.scoreDisplay{
font-size: 2rem;
}
.greenText, #playerScoreDisplay{
color: hsl(130, 84%, 54%);
}
.redText, #computerScoreDisplay{
color: hsl(0, 84%, 60%);
}