Skip to content

Commit

Permalink
Merge pull request #67 from varunlmxd/main
Browse files Browse the repository at this point in the history
Added Rock Paper Scissor game
  • Loading branch information
Chayandas07 authored Oct 26, 2023
2 parents ab75568 + 0d492a1 commit 05f9a8f
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 deletions.
Binary file added Rock Paper Scissor/0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Rock Paper Scissor/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Rock Paper Scissor/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions Rock Paper Scissor/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!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>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Rock Paper Scissor</h1>
<h3 class ="select">Select your choice</h3>
<div id="wrapper">
<button ><img src="0.jpg" id="0" width="60px"></button>
<button ><img src="1.jpg" id="1" width="60px"></button>
<button ><img src="2.jpg" id="2" width="60px"></button>
</div>
<h3 id="ai-answer"></h3>
<h3 id="your-answer"></h3>
<h3 id="Result"></h3>
<script src="script.js"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions Rock Paper Scissor/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const choice = document.querySelectorAll('button')
choice.forEach(choice => choice.addEventListener('click',result));

function result(id){
const ai = Math.floor(Math.random()*3)
console.log(id.target)
const player =Number(id.target.id)
const arr = ['Rock','Paper','Scissor']
document.getElementById("your-answer").innerText = "YOU : "+arr[player]
document.getElementById("ai-answer").innerText = "AI : "+arr[ai]
console.log(ai,player)
if(ai == player)
document.getElementById("Result").innerText = "DRAW"
if(ai ==0 && player ==1)
document.getElementById("Result").innerText = "YOU WON!"
else if(ai ==0 && player ==2)
document.getElementById("Result").innerText = "YOU LOST!"
if(ai ==1 && player ==2)
document.getElementById("Result").innerText = "YOU WON!"
else if(ai ==1 && player ==0)
document.getElementById("Result").innerText = "YOU LOST!"
if(ai ==2 && player ==0)
document.getElementById("Result").innerText = "YOU WON!"
else if(ai ==2 && player ==1)
document.getElementById("Result").innerText = "YOU LOST!"
}
9 changes: 9 additions & 0 deletions Rock Paper Scissor/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
body{
font-family:Arial, Helvetica, sans-serif;
text-align: center;
background-color: rgba(148, 184, 117, 0.804);
}
button{
padding: 0;
margin: 10px;
}

0 comments on commit 05f9a8f

Please sign in to comment.