-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (48 loc) · 1.79 KB
/
index.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
let a = document.querySelector(".btn1");
let b = document.querySelector(".btn2");
let c = document.querySelector(".btn3");
let e = document.querySelector(".score");
let i = document.querySelector(".wonlost");
let j = document.querySelector(".btn4");
let count=0;
function react(bn){
let arr=["Paper", "Stone", "Scissor"];
let d = Math.floor(Math.random()*3);
let g = arr[d];
let h =bn.textContent;
console.log(g);
if(h==g)
{
i.textContent ="Uff,It's a draw!" ;
}
else if(h=="Scissor" && g=="Paper")
{
i.textContent ="Congratulations,you won! Hurray" ;
count++;
e.innerHTML = `${count}`;
}
else if(h=="Stone" && g=="Scissor" )
{
i.textContent ="Congratulations,you won! Hurray" ;
count++;
e.innerHTML = `${count}`;
}
else if(h=="Paper" && g=="Stone")
{
i.textContent ="Congratulations,you won! Hurray" ;
count++;
e.innerHTML = `${count}`;
}
else
{
i.textContent ="Uff,You lost!" ;
}
}
j.addEventListener("click",function exit(){
count = 0;
e.innerHTML = `${count}`;
i.textContent ="Thanks for playing" ;
})
a.addEventListener("click",function reac(){react(a)});
b.addEventListener("click",function reac(){react(b)});
c.addEventListener("click",function rect(){react(c)});