-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
149 lines (129 loc) · 5.89 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<div class="container">
<div class="jumbotron">
<h3>
<center>
<div class="row row-margin">
<div class="col-md-3"></div>
<div class="col-md-6 btn-align">
<input type="button" class="btn btn-info btn-lg btn-size" onclick="choose(this.value)" value="Rock">
</input>
<input type="button" class="btn btn-info btn-lg btn-size" onclick="choose(this.value)" value="Paper">
</input>
<input type="button" class="btn btn-info btn-lg btn-size" onclick="choose(this.value)" value="Scissors">
</input>
</div>
<div class="col-md-3"></div>
</div>
<div id="game">
</div>
</center>
</h3>
</div>
</div>
<script>
var computerChoices = ["r", "p", "s"];
var wins = 0;
var losses = 0;
var ties = 0;
var userGuess = '';
function choose(value)
{
var userGuess = value[0].toLowerCase();
var computerGuess = computerChoices[Math.floor(Math.random() * computerChoices.length)];
if ((userGuess === "r") && (computerGuess === "s")) {
wins++;
} else if ((userGuess === "p") && (computerGuess === "r")) {
wins++;
} else if ((userGuess === "s") && (computerGuess === "p")) {
wins++;
} else if ((userGuess === "s") && (computerGuess === "r")) {
losses++;
} else if ((userGuess === "r") && (computerGuess === "p")) {
losses++;
} else if ((userGuess === "p") && (computerGuess === "s")) {
losses++;
} else {
ties++;
}
switch (computerGuess) {
case "r":
computerDisplay = '<span class="glyphicon glyphicon-cloud glyphicon-rock glyph-color" aria-hidden="true"></span>';
break;
case "p":
computerDisplay = '<span class="glyphicon glyphicon-file glyph-color" aria-hidden="true"></span>';
break;
case "s":
computerDisplay = '<span class="glyphicon glyphicon-scissors glyph-color" aria-hidden="true"></span>';
break;
}
switch (userGuess) {
case "r":
userDisplay = '<span class="glyphicon glyphicon-cloud glyphicon-rock glyph-color" aria-hidden="true"></span>';
break;
case "p":
userDisplay = '<span class="glyphicon glyphicon-file glyph-color" aria-hidden="true"></span>';
break;
case "s":
userDisplay = '<span class="glyphicon glyphicon-scissors glyph-color" aria-hidden="true"></span>';
break;
}
var html =
'<div class="row row-margin-sm">' +
'<div class="col-md-3"></div>' +
'<div class="col-md-3">' +
'<div class="panel panel-info">' +
'<div class="panel-heading">You</div>' +
'<div class="panel-body">' + userDisplay + '</div>' +
'</div>' +
'</div>' +
'<div class="col-md-3">' +
'<div class="panel panel-info">' +
'<div class="panel-heading">Computer</div>' +
'<div class="panel-body">' + computerDisplay + '</div>' +
'</div>' +
'</div>' +
'</div>' +
'<div class="row">' +
'<div class="col-md-3"></div>' +
'<div class="col-md-6">' +
'<div class="progress">' +
'<div class="progress-bar progress-bar-success bar-style" role="progressbar" aria-valuenow="' + wins + '" aria-valuemin="0" aria-valuemax="100" style="width: ' + wins + '%">' +
wins +
'<span class="sr-only">' + wins + '% Complete (success)</span>' +
'</div>' +
'</div>' +
'<div class="progress">' +
'<div class="progress-bar progress-bar-danger bar-style" role="progressbar" aria-valuenow="' + losses + '" aria-valuemin="0" aria-valuemax="100" style="width: ' + losses + '%">' +
losses +
'<span class="sr-only">' + losses + '% Complete (danger)</span>' +
'</div>' +
'</div>' +
'<div class="progress">' +
'<div class="progress-bar progress-bar-warning bar-style" role="progressbar" aria-valuenow="' + ties + '" aria-valuemin="0" aria-valuemax="100" style="width: ' + ties + '%">' +
ties +
'<span class="sr-only">' + ties + '% Complete (warning)</span>' +
'</div>' +
'</div>' +
'</div>' +
'</div>'
;
document.querySelector("#game").innerHTML = html;
};
// Math.floor(Math.random() * 3)
// for (var i = 0; i < 1; i++) {
// console.log(RPSrules[Math.floor(Math.random() * 3)]);
// }
</script>
</body>
</html>