-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sandhya1102
committed
Aug 30, 2024
0 parents
commit 0ea0dcd
Showing
6 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
let userScore=0; | ||
let compScore=0; | ||
|
||
const choices=document.querySelectorAll(".choice"); | ||
const msg=document.querySelector(".msg"); | ||
const userscore=document.querySelector("#user-score"); | ||
const compscore=document.querySelector("#comp-score"); | ||
|
||
const gencompChoice=()=>{ | ||
const options=["rock","paper","Scissor"]; | ||
const randomid=Math.floor(Math.random()*3); | ||
return options[randomid]; | ||
}; | ||
|
||
const drawgame=()=>{ | ||
msg.innerText="Draw ,play again"; | ||
msg.style.backgroundColor="#c20d67a8"; | ||
}; | ||
|
||
const showWinner=(userWin,userchoice,compchoice)=>{ | ||
if(userWin){ | ||
userScore++; | ||
userscore.innerText=userScore; | ||
msg.innerText=`you win! your ${userchoice} beats ${compchoice}`; | ||
msg.style.backgroundColor="green"; | ||
}else{ | ||
compScore++; | ||
compscore.innerText=compScore; | ||
msg.innerText=`you lost! ${compchoice} beats your ${userchoice}`;; | ||
msg.style.backgroundColor="red"; | ||
} | ||
}; | ||
|
||
const playGames=(userchoice)=>{ | ||
const compchoice=gencompChoice(); | ||
if(userchoice===compchoice){ | ||
drawgame();//draw game | ||
}else{ | ||
let userWin=true;{ | ||
if(userchoice==="rock"){//paper,scissor | ||
userWin=compchoice==="paper"?false:true; | ||
} else if(userchoice==="paper"){//rock,scissor | ||
userWin=compchoice==="Scissor"?false:true; | ||
}else{ | ||
userWin=compchoice==="rock"?false:true; | ||
} | ||
showWinner(userWin,userchoice,compchoice); | ||
|
||
}; | ||
|
||
}; | ||
}; | ||
|
||
|
||
choices.forEach((choice)=>{ | ||
choice.addEventListener("click",()=>{ | ||
const userchoice=choice.getAttribute("id"); | ||
playGames(userchoice); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!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="style.css"> | ||
</head> | ||
<body> | ||
<h1>Rock Paper Scissor</h1> | ||
<div class="choices"> | ||
<div class="choice" id="rock"> | ||
<img src="pics/rock.png"> | ||
</div> | ||
<div class="choice" id="paper"> | ||
<img src="pics/paper.png"> | ||
</div> | ||
<div class="choice" id="Scissor"> | ||
<img src="pics/scissors.png"> | ||
</div> | ||
</div> | ||
<div class="score-board"> | ||
<div class="score"> | ||
<p id="user-score">0</p> | ||
<p>You</p> | ||
</div> | ||
<div class="score"> | ||
<p id="comp-score">0</p> | ||
<p>Computer</p> | ||
</div> | ||
</div> | ||
<div class="msg-container"> | ||
<div class="msg">Play your move</div> | ||
</div> | ||
<script src="app.js"></script> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
*{ | ||
margin:0; | ||
padding:0; | ||
} | ||
body { | ||
background-color: rgb(180, 80, 80); | ||
text-align: center; | ||
} | ||
h1{ | ||
color: azure; | ||
box-sizing: border-box; | ||
padding:10px; | ||
text-align: center; | ||
text-decoration:solid; | ||
font-family:Verdana; | ||
font-style: italic; | ||
} | ||
|
||
.choices{ | ||
display: flex; | ||
justify-content: center; | ||
margin-top:60px; | ||
gap: 3rem; | ||
} | ||
|
||
.choice:hover{ | ||
cursor: pointer; | ||
background-color: rgb(11, 12, 31); | ||
} | ||
|
||
img{ | ||
height: 200px; | ||
width: 200px; | ||
object-fit: cover; | ||
border-radius: 50%; | ||
box-shadow:0 0 1rem black; | ||
|
||
} | ||
|
||
.score-board{ | ||
display: flex; | ||
justify-content: center; | ||
margin-top: 20px; | ||
padding: 20px; | ||
font-size: xx-large; | ||
gap:3rem; | ||
} | ||
#user-score,#comp-score{ | ||
font-size: 4rem; | ||
} | ||
.msg-container{ | ||
margin: 20px; | ||
} | ||
.msg{ | ||
font-size: 2rem; | ||
background-color: #0c0609a8; | ||
color: blanchedalmond; | ||
display: inline-block; | ||
border: 1px solid #120f2e; | ||
border-radius: 0.5rem; | ||
padding: 10px; | ||
|
||
} | ||
|
||
.msg:hover{ | ||
cursor: pointer; | ||
background-color: rgb(22, 20, 163); | ||
} |