-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
59 lines (57 loc) · 2.13 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
console.log(Math.floor(Math.random() * 3 + 1));
const bola = ["./harry.png", "./hermione.png", "./ron.png"];
function handleClick(item) {
document.getElementById('image-player').className = 'letsgo';
document.getElementById('image-enemy').className = 'letsgo';
if (item === 'harry') {
const enemy = bola[Math.floor(Math.random() * 3 + 1) - 1];
document.getElementById("image-player").src = "./harry.png";
document.getElementById("image-enemy").src = enemy;
document.getElementById("result").innerHTML = checkWinner(item, enemy);
} else if (item === 'hermione') {
const enemy = bola[Math.floor(Math.random() * 3 + 1) - 1];
document.getElementById("image-player").src = "./hermione.png";
document.getElementById("image-enemy").src = enemy;
document.getElementById("result").innerHTML = checkWinner(item, enemy);
} else if (item === 'ron') {
const enemy = bola[Math.floor(Math.random() * 3 + 1) - 1];
document.getElementById("image-player").src = "./ron.png";
document.getElementById("image-enemy").src = enemy;
document.getElementById("result").innerHTML = checkWinner(item, enemy);
}
}
function checkWinner(player, enemy) {
if (player === "harry") {
if (enemy === "./hermione.png") {
return "lose";
}
if (enemy === "./ron.png") {
return "win";
}
if (enemy === "./harry.png") {
return "draw";
}
}
if (player === "hermione") {
if (enemy === "./ron.png") {
return "lose";
}
if (enemy === "./harry.png") {
return "win";
}
if (enemy === "./hermione.png") {
return "draw";
}
}
if (player === "ron") {
if (enemy === "./harry.png") {
return 'lose';
}
if (enemy === "./hermione.png") {
return 'win';
}
if (enemy === "./ron.png") {
return "draw";
}
}
}