-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
69 lines (69 loc) · 2.12 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
var choices = ["paper", "rock", "scissors"];
var i = Math.floor(Math.random() * 3);
var ComChoice = choices[i];
var UserPoints = 0;
var ComPoints = 0;
function score(){
var score_div = document.getElementById("score").innerHTML = UserPoints + " - " + ComPoints;
}
setInterval(score, 50);
function convert(word){
if(word === "paper") return '<i class="far fa-hand-paper"></i>';
if(word === "rock") return '<i class="far fa-hand-rock"></i>';
return '<i class="far fa-hand-scissors"></i>'
}
function game(UserChoice){
var box = document.getElementById("challenge");
box.style.display = "inline-flex";
var userDiv = document.getElementById("YourObject");
userDiv.innerHTML = convert(UserChoice);
var comDiv = document.getElementById("ComObject");
comDiv.innerHTML = convert(ComChoice);
if(UserChoice === "paper" && ComChoice === "rock" || UserChoice === "rock" && ComChoice === "scissors" || UserChoice === "scissors" && ComChoice === "paper"){
win(UserChoice);
}
else if(UserChoice === ComChoice){
draw(UserChoice);
}
else{
lose(UserChoice);
}
function continuGame(){
i = Math.floor(Math.random() * 3);
ComChoice = choices[i];
box.style.display = "none";
}
setTimeout(continuGame, 1200);
}
function win(bn){
UserPoints++;
document.getElementById("who").innerHTML = "You win!";
var bn = document.getElementById(bn);
bn.classList.remove("bn");
bn.classList.add("green");
setTimeout(() => {
bn.classList.add("bn");
bn.classList.remove("green");
}, 1200);
}
function draw(bn){
document.getElementById("who").innerHTML = "It's a Draw.";
var bn = document.getElementById(bn);
bn.classList.remove("bn");
bn.classList.add("gray");
setTimeout(() => {
bn.classList.add("bn");
bn.classList.remove("gray");
}, 1200);
}
function lose(bn){
ComPoints++;
document.getElementById("who").innerHTML = "You lose...";
var bn = document.getElementById(bn);
bn.classList.remove("bn");
bn.classList.add("red");
setTimeout(() => {
bn.classList.add("bn");
bn.classList.remove("red");
}, 1200);
}