-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrock-paper(css+js).html
More file actions
94 lines (83 loc) · 2.68 KB
/
rock-paper(css+js).html
File metadata and controls
94 lines (83 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rock-Paper-Scissor</title>
<style>
body {
height: 100%;
margin:0px;
background-color: #f2f2f2;
}
#container {
top:50%;
left: 50%;
width: 300px;
background-color: white;
padding: 20px;
border-radius: 10px;
}
button {
margin: 10px;
padding: 10px;
border: none;
border-radius: 5px;
cursor: pointer;
height: 50px;
width: 50px;
font-size: 25px;
background-color: rgb(0, 149, 200);
}
button:hover{
background-color: rgb(0, 102, 255);
}
h1 {
margin-bottom: 20px;
text-align: center;
}
h2 {
margin-bottom: 10px;
}
#resultid{
font-size: 24px;
color: red;
}
</style>
</head>
<body>
<h1>Rock-Paper-Scissor</h1>
<div id="container">
<button id="rock" onclick="playgame('rock')">👊</button>
<button id="paper" onclick="playgame('paper')">✋</button>
<button id="scissor" onclick="playgame('scissor')">✌️</button>
<h2 id="player-points">Player:</h2>
<h2 id="computer-points">Computer:</h2>
<h2 id="resultid">Result:</h2>
</div>
<script>
const choices=["rock", "paper", "scissor"];
var result=document.getElementById("resultid");
var playerPoints=document.getElementById("player-points");
var computerPoints=document.getElementById("computer-points");
let playerScore=0;
let computerScore=0;
function playgame(playerchoice){
const computerchoice= choices[Math.floor(Math.random()*3)];
if(playerchoice===computerchoice){
result.textContent="Result: It's a TIE";
}
else if((playerchoice==="rock" && computerchoice==="scissor") || (playerchoice==="paper" && computerchoice==="rock") || (playerchoice==="scissor" && computerchoice==="paper")){
result.textContent="Result: Player WINS";
playerScore++;
playerPoints.textContent=`Player: ${playerScore}`;
}
else{
result.textContent="Result: Computer WINS";
computerScore++;
computerPoints.textContent=`Computer: ${computerScore}`;
}
}
</script>
</body>
</html>