-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
35 lines (35 loc) · 1.23 KB
/
script.js
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
let playerscore=document.querySelector(".playerscore");
let compscore=document.querySelector(".compscore");
let images=document.querySelectorAll(".container img");
let msgbox=document.querySelector(".display");
const choices=["Rock","Paper","Scissor"];
for(let i in images){
images[i].onmouseenter=()=>{
images[i].style.border="7px solid green";
images[i].style.borderRadius="50%";
}
images[i].onmouseleave=()=>{
images[i].style.removeProperty("border");
}
images[i].onclick=()=>{
let playerchoice=choices[i];
let compchoice=choices[Math.floor(Math.random()*3)];
winCheck(playerchoice,compchoice);
}
}
const winCheck=(p,c)=>{
if(p===c){
msgbox.innerText="It Was A Draw";
msgbox.style.backgroundColor="#14213d";
}
else if((p=="Rock" && c=="Scissor")||(p=="Paper" && c=="Rock")||(p=="Scissor" && c=="Paper")){
playerscore.innerText=parseInt(playerscore.innerText)+1;
msgbox.innerText=`You Won! ${p} beats ${c}`;
msgbox.style.backgroundColor="green";
}
else{
compscore.innerText=parseInt(compscore.innerText)+1;
msgbox.innerText=`You Lost! ${c} beats ${p}`;
msgbox.style.backgroundColor="red";
}
}