-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
164 lines (144 loc) · 4.37 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
function Validate (word) {
var lowerCase = word.toLowerCase();
if (lowerCase == "rock" || lowerCase == "paper" || lowerCase == "scissor" || lowerCase == "scissors") {
return true;
} else {
return false;
}
}
function CreateComputerChoice (input) {
var ccw;
if (input < 0.34) {
ccw = "rock";
} else if (input <= 0.67) {
ccw = "paper";
} else {
ccw = "scissor";
}
return ccw;
}
function ConvertScissors (word) {
if (word == "scissors") {
word = "scissor";
return word;
} else {
return word;
}
}
function Compare (user, computer) {
var case1 = "It's a Tie!";
var case2 = "Computer wins!";
var case3 = "You win!";
if (user == computer) {
return case1;
} else if (user == "rock" && computer == "paper") {
return case2;
} else if (user == "rock" && computer == "scissor") {
return case3;
} else if (user == "paper" && computer == "rock") {
return case3;
} else if (user == "paper" && computer == "scissor") {
return case2;
} else if (user == "scissor" && computer == "rock") {
return case2;
} else if (user == "scissor" && computer == "paper") {
return case3;
}
}
function ClearPictures () {
var youRock = document.getElementById("youRock")
var youPaper = document.getElementById("youPaper")
var youScissor = document.getElementById("youScissor")
var compRock = document.getElementById("compRock")
var compPaper = document.getElementById("compPaper")
var compScissor = document.getElementById("compScissor")
youRock.style.display = 'none';
youPaper.style.display = 'none';
youScissor.style.display = 'none';
compRock.style.display = 'none';
compPaper.style.display = 'none';
compScissor.style.display = 'none';
}
function ShowPicture () {
var youRock = document.getElementById("youRock")
var youPaper = document.getElementById("youPaper")
var youScissor = document.getElementById("youScissor")
var compRock = document.getElementById("compRock")
var compPaper = document.getElementById("compPaper")
var compScissor = document.getElementById("compScissor")
if (uc.value == "rock") {
youRock.style.display = "block";
} else if (uc.value == "paper") {
youPaper.style.display = "block";
} else {
youScissor.style.display = "block";
};
if (compChoice == "rock") {
compRock.style.display = "block";
} else if (compChoice == "paper") {
compPaper.style.display = "block";
} else {
compScissor.style.display = "block";
};
}
function Results (result) {
var resultH1 = document.getElementById("resultH1");
var youChoice = document.getElementById("youChoice");
var computerChoice = document.getElementById("computerChoice");
var resultHTML = document.getElementById("resultHTML");
var playAgain = document.getElementById("playAgain");
resultH1.innerHTML = "Results:";
youChoice.innerHTML = uc.value.toUpperCase();
youChoice.style.color = "#459ed0";
computerChoice.innerHTML = compChoice.toUpperCase();
computerChoice.style.color = "#459ed0";
resultHTML.innerHTML = result;
if (result == "Computer wins!") {
resultHTML.style.color = "#f16058";
} else if (result == "You win!") {
resultHTML.style.color = "#63bd65";
}
else {
resultHTML.style.color = "black";
}
playAgain.innerHTML = "Play again?";
}
function ClearText () {
var youChoice = document.getElementById("youChoice").style.display = 'none';
var computerChoice = document.getElementById("computerChoice").style.display = 'none';
var results = document.getElementById("results").style.display = 'none';
}
function Counter (input) {
if (input == "You win!") {
youWin++;
} else if (input == "Computer wins!") {
computerWin++;
} else {
tie++;
}
}
var youWin = 0;
var computerWin = 0;
var tie = 0;
function PlayGame () {
var uc = document.getElementById("uc").value;
var cc = Math.random();
ClearPictures();
var validateResult = Validate(uc);
var uc = ConvertScissors(uc);
if (validateResult) {
compChoice = CreateComputerChoice(cc);
ShowPicture();
var result = Compare(uc, compChoice);
Results(result);
} else {
var resultH1 = document.getElementById("resultH1").innerHTML = "Please enter a valid value.";
ClearPictures();
ClearText();
}
var resetInput = document.getElementById("uc").value = "";
Counter(result);
var youCount = document.getElementById("youCount").innerHTML = youWin;
var computerCount = document.getElementById("computerCount").innerHTML = computerWin;
var tieCount = document.getElementById("tieCount").innerHTML = tie;
}