-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
97 lines (76 loc) · 2.44 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
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
var won = 0;
var lost = 0;
document.getElementById("yourScore").innerHTML = won;
document.getElementById("compScore").innerHTML = lost;
function chooseP() {
userChoice = "Paper";
document.getElementById("p").style = 'border: 10px white solid;';
document.getElementById("k").style = 'border: none;';
document.getElementById("n").style = 'border: none;';
}
function chooseK() {
userChoice = "Rock";
document.getElementById("k").style = 'border: 10px white solid;';
document.getElementById("p").style = 'border: none;';
document.getElementById("n").style = 'border: none;';
}
function chooseN() {
userChoice = "Scissors";
document.getElementById("n").style = 'border: 10px white solid;';
document.getElementById("p").style = 'border: none;';
document.getElementById("k").style = 'border: none;';
}
function play(){
var defaultCompChoice = Math.random();
var compChoice = defaultCompChoice * 3;
if (compChoice < 1) {
compChoice = "Rock";
}
else if (compChoice > 2) {
compChoice = "Scissors";
}
else {
compChoice = "Paper";
}
if (userChoice === compChoice) {
document.getElementById("results").innerHTML = "Draw";
}
else if (compChoice === "Rock") {
if (userChoice === "Paper") {
document.getElementById("results").innerHTML = "You won! Computer choice was " + compChoice;
won++; }
else {
document.getElementById("results").innerHTML = "You lost! Computer choice was " + compChoice;
lost++; }
}
else if (compChoice === "Scissors") {
if (userChoice === "Paper") {
document.getElementById("results").innerHTML = "You lost! Computer choice was " + compChoice;
lost++; }
else {
document.getElementById("results").innerHTML = "You won! Computer choice was " + compChoice;
won++; }
}
else {
if (userChoice === "Rock") {
document.getElementById("results").innerHTML = "You lost! Computer choice was " + compChoice;
lost++; }
else {
document.getElementById("results").innerHTML = "You won! Computer choice was " + compChoice;
won++; }
}
document.getElementById("yourScore").innerHTML = won;
document.getElementById("compScore").innerHTML = lost;
}
function resetGame(){
won = 0;
lost = 0;
defaultCompChoice = 0;
userChoice = 0;
document.getElementById("p").style = 'border: none;';
document.getElementById("n").style = 'border: none;';
document.getElementById("k").style = 'border: none;';
document.getElementById("results").innerHTML = "";
document.getElementById("yourScore").innerHTML = won;
document.getElementById("compScore").innerHTML = lost;
}