-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
50 lines (49 loc) · 1.37 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function randomanswer(user){
var game_list = ["rock","scissors","paper"]
var randomnum = Math.floor(Math.random() * 3);
var computer = game_list[randomnum]
var result
if (computer == user) {
result = 'Draw'
}else{
if(user == "rock"){
if(computer == "scissors"){
result = 'Win'
}else{
result = 'Lose'
}
}else if(user == "paper"){
if(computer == "scissors"){
result = "Lose"
}else{
result = "Win"
}
}else if(user == "scissors"){
if(computer == "rock"){
result ="Lose"
}else{
result = "Win"
}
}
}
addscore(result)
document.querySelector('.result').textContent = result
togglemodal()
}
const togglemodal = () => {
document.querySelector('#modal').classList.toggle('open')
document.querySelector('#overlay').classList.toggle('open')
}
var user = 0
var computer = 0
document.getElementById("player").textContent = user ;
document.getElementById("computer").textContent = computer ;
const addscore = (result) => {
if(result == "Win"){
user++
}else if(result == "Lose"){
computer++
}
document.getElementById("player").textContent = user ;
document.getElementById("computer").textContent = computer ;
}