Skip to content

Commit 05f9a8f

Browse files
authored
Merge pull request #67 from varunlmxd/main
Added Rock Paper Scissor game
2 parents ab75568 + 0d492a1 commit 05f9a8f

File tree

6 files changed

+57
-0
lines changed

6 files changed

+57
-0
lines changed

Rock Paper Scissor/0.jpg

12.9 KB
Loading

Rock Paper Scissor/1.jpg

13.2 KB
Loading

Rock Paper Scissor/2.jpg

14 KB
Loading

Rock Paper Scissor/index.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Rock Paper Scissor</title>
7+
<link rel="stylesheet" href="styles.css">
8+
</head>
9+
<body>
10+
<h1>Rock Paper Scissor</h1>
11+
<h3 class ="select">Select your choice</h3>
12+
<div id="wrapper">
13+
<button ><img src="0.jpg" id="0" width="60px"></button>
14+
<button ><img src="1.jpg" id="1" width="60px"></button>
15+
<button ><img src="2.jpg" id="2" width="60px"></button>
16+
</div>
17+
<h3 id="ai-answer"></h3>
18+
<h3 id="your-answer"></h3>
19+
<h3 id="Result"></h3>
20+
<script src="script.js"></script>
21+
</body>
22+
</html>

Rock Paper Scissor/script.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const choice = document.querySelectorAll('button')
2+
choice.forEach(choice => choice.addEventListener('click',result));
3+
4+
function result(id){
5+
const ai = Math.floor(Math.random()*3)
6+
console.log(id.target)
7+
const player =Number(id.target.id)
8+
const arr = ['Rock','Paper','Scissor']
9+
document.getElementById("your-answer").innerText = "YOU : "+arr[player]
10+
document.getElementById("ai-answer").innerText = "AI : "+arr[ai]
11+
console.log(ai,player)
12+
if(ai == player)
13+
document.getElementById("Result").innerText = "DRAW"
14+
if(ai ==0 && player ==1)
15+
document.getElementById("Result").innerText = "YOU WON!"
16+
else if(ai ==0 && player ==2)
17+
document.getElementById("Result").innerText = "YOU LOST!"
18+
if(ai ==1 && player ==2)
19+
document.getElementById("Result").innerText = "YOU WON!"
20+
else if(ai ==1 && player ==0)
21+
document.getElementById("Result").innerText = "YOU LOST!"
22+
if(ai ==2 && player ==0)
23+
document.getElementById("Result").innerText = "YOU WON!"
24+
else if(ai ==2 && player ==1)
25+
document.getElementById("Result").innerText = "YOU LOST!"
26+
}

Rock Paper Scissor/styles.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
body{
2+
font-family:Arial, Helvetica, sans-serif;
3+
text-align: center;
4+
background-color: rgba(148, 184, 117, 0.804);
5+
}
6+
button{
7+
padding: 0;
8+
margin: 10px;
9+
}

0 commit comments

Comments
 (0)