-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
87 lines (79 loc) · 2.06 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var items = document.querySelectorAll(".game-element")
var score = document.getElementById("score")
var game_div = document.getElementById("game")
var result_div = document.getElementById("chosen")
var play_btn = document.getElementById("play")
var statuse = document.getElementById("status_res")
var uc = document.getElementById("uc")
var bc = document.getElementById("bc")
let uscore = 0
items.forEach(item => item.addEventListener("click",()=>{
var y = item.id
var z = bchoice();
if(y===z){
statuse.innerHTML = "ITS TIE"
}
else if(y=="rock"&&z=="scissor"||y=="paper"&&z=="rock"||y=="scissor"&&z=="paper"){
uscore = uscore + 1;
statuse.innerHTML = " YOU WIN"
}
else{
uscore = uscore - 1;
statuse.innerHTML = " YOU LOSE"
}
game_div.style.display = "none"
result_div.style.display = "flex"
if(y=="rock"){
console.log("rock")
uc.classList.add("rock")
uc.classList.remove("paper")
uc.classList.remove("scissor")
}
else if(y=="paper"){
console.log("paper")
uc.classList.add("paper")
uc.classList.remove("rock")
uc.classList.remove("scissor")
}
else if(y=="scissor"){
console.log("scissor")
uc.classList.add("scissor")
uc.classList.remove("rock")
uc.classList.remove("paper")
}
else{
console.log("CHOOSE ANOTHER")
}
if(z=="rock"){
console.log("rock")
bc.classList.add("rock")
bc.classList.remove("paper")
bc.classList.remove("scissor")
}
else if(z=="paper"){
console.log("paper")
bc.classList.add("paper")
bc.classList.remove("rock")
bc.classList.remove("scissor")
}
else if(z=="scissor"){
console.log("scissor")
bc.classList.add("scissor")
bc.classList.remove("rock")
bc.classList.remove("paper")
}
else{
console.log("CHOOSE ANOTHER")
}
score.innerHTML = uscore
}))
function bchoice(){
var array = ["rock","paper","scissor"]
var x = Math.floor(Math.random()*3)
return array[x]
}
play_btn.addEventListener("click",playGame)
function playGame(){
game_div.style.display = "flex"
result_div.style.display = "none"
}