-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
122 lines (84 loc) · 3.14 KB
/
script.js
File metadata and controls
122 lines (84 loc) · 3.14 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
var finish = true;
function end() {
finish = false;
return finish;
}
var rockbutton = document.getElementById("rockid");
rockbutton.onclick = function() {
userChoice = "rock";
abc();
};
var scissorsbutton = document.getElementById("scissorsid");
scissorsbutton.onclick = function() {
userChoice = "scissors";
abc();
};
var paperbutton = document.getElementById("paperid");
paperbutton.onclick = function() {
userChoice = "paper";
abc();
};
function abc() {
if (finish) {
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if (computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
var compare = function(choice1, choice2) {
if (choice1 === choice2) {
return "The result is a tie!";
} else if (choice1 === "rock") {
if (choice2 === "scissors") {
return "Rock Wins"
} else {
return "Paper Wins"
}
} else if (choice1 === "paper") {
if (choice2 === "rock") {
return "Paper Wins"
} else {
return "scissorsssors Wins"
}
} else {
if (choice2 === "rock") {
return "Rock Wins"
} else {
return "scissorsssors Wins"
}
}
};
if (userChoice === "paper") {
document.getElementById("paperid").className += " showclass";
} else if (userChoice === "rock") {
document.getElementById("rockid").className += " showclass";
} else if (userChoice === "scissors") {
document.getElementById("scissorsid").className += " showclass";
}
if (computerChoice === "paper") {
document.getElementById("paperid").className += " showclass";
} else if (computerChoice === "rock") {
document.getElementById("rockid").className += " showclass";
} else if (computerChoice === "scissors") {
document.getElementById("scissorsid").className += " showclass";
}
setTimeout(function() {
showText(compare(userChoice, computerChoice) + " " + "-- You Chose: " + userChoice + "-- Computer Chose: " + computerChoice);
var x = document.getElementById('restart');
x.style.visibility = 'visible';
end();
}, 1500);
document.getElementById("every").className += " everymore";
setTimeout(function() {
document.getElementById("rockid").className += " noneclass";
document.getElementById("paperid").className += " noneclass";
document.getElementById("scissorsid").className += " noneclass";
}, 1500);
};
function showText(text) {
document.getElementById("result").innerText = text;
}
}