-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
61 lines (53 loc) · 1.57 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
50
51
52
53
54
55
56
57
58
59
60
61
let [computer_score, user_score] = [0, 0];
let result_ref = document.getElementById("result");
let btn_restart = document.getElementById("restart");
let weapons = document.getElementById("weapons");
let choices_object = {
rock: {
rock: "draw",
scissor: "win",
paper: "lose",
},
scissor: {
rock: "lose",
scissor: "draw",
paper: "win",
},
paper: {
rock: "win",
scissor: "lose",
paper: "draw",
},
};
function checker(input) {
var choices = ["rock", "paper", "scissor"];
var num = Math.floor(Math.random() * 3);
document.getElementById(
"comp_choice"
).innerHTML = ` Computer choose <span> ${choices[num].toUpperCase()} </span>`;
document.getElementById(
"user_choice"
).innerHTML = ` You choose <span> ${input.toUpperCase()} </span>`;
let computer_choice = choices[num];
switch (choices_object[input][computer_choice]) {
case "win":
result_ref.style.cssText = "background-color: #cefdce; color: #689f38";
result_ref.innerHTML = "YOU WIN";
user_score++;
break;
case "lose":
result_ref.style.cssText = "background-color: #ffdde0; color: #d32f2f";
result_ref.innerHTML = "YOU LOSE";
computer_score++;
break;
default:
result_ref.style.cssText = "background-color: #e5e5e5; color: #808080";
result_ref.innerHTML = "DRAW";
break;
}
document.getElementById("computer_score").innerHTML = computer_score;
document.getElementById("user_score").innerHTML = user_score;
weapons.addEventListener("click", () => {
btn_restart.style.display = "block";
});
}