-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
70 lines (58 loc) · 1.71 KB
/
app.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
const buttonRock = document.getElementById('rock');
const buttonPaper = document.getElementById('paper');
const buttonSciss = document.getElementById('sciss');
const yourChoise = document.getElementById("youChose");
const button = document.getElementById("button");
const computer = document.getElementById("computer");
const won = document.getElementById("won");
const reset = document.getElementById("reset")
let index
let yourNum
function changeRock() {
yourChoise.innerHTML="Rock"
yourNum = 0
}
function changePaper() {
yourChoise.innerHTML="Paper"
yourNum = 1
}
function changeSciss() {
yourChoise.innerHTML="Scissors"
yourNum = 2
}
function random() {
index = Math.random() * 3;
index = Math.floor(index);
if (index==0) {
computer.innerHTML="Rock"
} else if (index==1) {
computer.innerHTML="Paper"
} else {
computer.innerHTML="Scissors"
}
if (index==yourNum) {
won.innerHTML="Tie!"
}else if (index==0 && yourNum==1) {
won.innerHTML="You won!"
}else if (index==0 && yourNum==2) {
won.innerHTML="You lost!"
}else if (index==1 && yourNum==0) {
won.innerHTML="You lost!"
}else if (index==2 && yourNum==0) {
won.innerHTML="You won!"
}else if (index==1 && yourNum==2) {
won.innerHTML="You won!"
}else if (index==2 && yourNum==1) {
won.innerHTML="You lost!"
}
}
function resetAll() {
won.innerHTML=""
computer.innerHTML=""
yourChoise.innerHTML=""
}
reset.addEventListener("click", resetAll)
buttonRock.addEventListener("click", changeRock);
buttonPaper.addEventListener("click", changePaper);
buttonSciss.addEventListener("click", changeSciss);
button.addEventListener("click", random)