-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
71 lines (63 loc) · 2.42 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
71
var pc_rock = (document.getElementsByClassName("computer").src =
"./img/rock.png");
var pc_paper = (document.getElementsByClassName("computer").src =
"./img/paper.png");
var pc_scissor = (document.getElementsByClassName("computer").src =
"./img/scissor.png");
var player_rock = (document.getElementsByClassName("player").src =
"./img/rock.png");
var player_paper = (document.getElementsByClassName("player").src =
"./img/paper.png");
var player_scissor = (document.getElementsByClassName("player").src =
"./img/scissor.png");
var items = [pc_rock, pc_paper, pc_scissor];
function any() {
var any_item = items[Math.floor(Math.random() * 3)];
var random = document
.getElementById("computer")
.setAttribute("src", any_item);
return any_item;
}
function main() {
let rock = document
.getElementById("rock")
.addEventListener("click", function () {
document.getElementById("player").setAttribute("src", player_rock);
let any_rock = any();
if (player_rock === any_rock) {
document.getElementById("result").innerHTML = "its tie";
} else if (player_paper === any_rock) {
document.getElementById("result").innerHTML = "Computer win";
} else {
document.getElementById("result").innerHTML = "Player win";
}
});
let paper = document
.getElementById("paper")
.addEventListener("click", function () {
document.getElementById("player").setAttribute("src", player_paper);
let any_paper = any();
if (player_paper === any_paper) {
document.getElementById("result").innerHTML = "its tie";
} else if (player_scissor === any_paper) {
document.getElementById("result").innerHTML = "Computer win";
} else {
document.getElementById("result").innerHTML = "Player win";
}
});
let scissor = document
.getElementById("scissor")
.addEventListener("click", function () {
document.getElementById("player").setAttribute("src", player_scissor);
let any_scissor = any();
if (player_scissor === any_scissor) {
document.getElementById("result").innerHTML = "its tie";
console.log("tie");
} else if (player_rock === any_scissor) {
document.getElementById("result").innerHTML = "Computer win";
} else {
document.getElementById("result").innerHTML = "Player win";
}
});
}
main();