-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
75 lines (60 loc) · 3.61 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
document.getElementById("rockBtn").addEventListener("click", showRock);
document.getElementById("paperBtn").addEventListener("click", showPaper);
document.getElementById("scissorsBtn").addEventListener("click", showScissors);
document.getElementById("ComputerBtn").addEventListener("click", showRandom);
document.getElementById("resetBtn").addEventListener("click", resetFields);
let rock = '<i class=\"fas fa-hand-rock fa-4x\"></i>';
let paper = '<i class=\"fas fa-hand-paper fa-4x\"></i>';
let scissors = '<i class=\"fas fa-hand-scissors fa-4x\">';
let computerChoice = [
'<i class="fas fa-hand-rock fa-4x" aria-hidden="true"></i>',
'<i class="fas fa-hand-paper fa-4x" aria-hidden="true"></i>',
'<i class="fas fa-hand-scissors fa-4x" aria-hidden="true"></i>'
];
function showRock() {
document.getElementById("iconArea").innerHTML = rock;
document.getElementById("computerIconArea").innerHTML = " ";
document.getElementById("ResultTextArea").innerHTML = " ";
}
function showPaper() {
document.getElementById("iconArea").innerHTML = paper;
document.getElementById("computerIconArea").innerHTML = " ";
document.getElementById("ResultTextArea").innerHTML = " ";
}
function showScissors() {
document.getElementById("iconArea").innerHTML = scissors;
document.getElementById("computerIconArea").innerHTML = " ";
document.getElementById("ResultTextArea").innerHTML = " ";
}
function showRandom() {
let rand = computerChoice[Math.floor(Math.random() * computerChoice.length)];
document.getElementById("computerIconArea").innerHTML = rand;
compareFields();
}
function resetFields() {
document.getElementById("iconArea").innerHTML = " ";
document.getElementById("computerIconArea").innerHTML = " ";
document.getElementById("ResultTextArea").innerHTML = " "
}
function compareFields() {
let playerResult = document.getElementById("iconArea").innerHTML;
let computerResult = document.getElementById("computerIconArea").innerHTML;
if (playerResult === computerResult) {
document.getElementById("ResultTextArea").innerHTML = "DRAW"
}
if (playerResult === "<i class=\"fas fa-hand-rock fa-4x\" aria-hidden=\"true\"></i>" && computerResult === "<i class=\"fas fa-hand-paper fa-4x\" aria-hidden=\"true\"></i>") {
document.getElementById("ResultTextArea").innerHTML = "YOU LOSE!"
} else if (playerResult === "<i class=\"fas fa-hand-rock fa-4x\" aria-hidden=\"true\"></i>" && computerResult === "<i class=\"fas fa-hand-scissors fa-4x\" aria-hidden=\"true\"></i>") {
document.getElementById("ResultTextArea").innerHTML = "YOU WIN!"
}
if (playerResult === "<i class=\"fas fa-hand-paper fa-4x\" aria-hidden=\"true\"></i>" && computerResult === "<i class=\"fas fa-hand-scissors fa-4x\" aria-hidden=\"true\"></i>") {
document.getElementById("ResultTextArea").innerHTML = "YOU LOSE!"
} else if (playerResult === "<i class=\"fas fa-hand-paper fa-4x\" aria-hidden=\"true\"></i>" && computerResult === "<i class=\"fas fa-hand-rock fa-4x\" aria-hidden=\"true\"></i>") {
document.getElementById("ResultTextArea").innerHTML = "YOU WIN!"
}
if (playerResult === "<i class=\"fas fa-hand-scissors fa-4x\" aria-hidden=\"true\"></i>" && computerResult === "<i class=\"fas fa-hand-rock fa-4x\" aria-hidden=\"true\"></i>") {
document.getElementById("ResultTextArea").innerHTML = "YOU LOSE!"
} else if (playerResult === "<i class=\"fas fa-hand-scissors fa-4x\" aria-hidden=\"true\"></i>" && computerResult === "<i class=\"fas fa-hand-paper fa-4x\" aria-hidden=\"true\"></i>") {
document.getElementById("ResultTextArea").innerHTML = "YOU WIN!"
}
}