-
Notifications
You must be signed in to change notification settings - Fork 0
/
rps.html
60 lines (58 loc) · 2.36 KB
/
rps.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
<!DOCTYPE HTML>
<html>
<head>
<script>
function computerPlay() {
var choices = ['rock', 'paper', 'scissors'];
var randomPlay = Math.floor(Math.random()*choices.length);
return choices[randomPlay];
}
var computerSelection = computerPlay;
var playerSelection;
var wins = 0;
var losses = 0;
var draws = 0;
function playRound(playerSelection, computerSelection) {
var playerSelection = prompt("Rock, Paper, or Scissors?");
playerSelection = playerSelection.toLowerCase();
if(playerSelection === computerSelection) {
draws++;
alert("It is a tie.");
}
else if(playerSelection === 'rock' && computerSelection === 'scissor') {
wins++;
alert("You win! Rock beats Scissors.");
}
else if(playerSelection === 'paper' && computerSelection === 'rock') {
wins++;
alert("You win! Paper beats Rock.");
}
else if (playerSelection == 'scissors' && computerSelection == 'paper') {
wins++;
alert("You win! Scissors beats Paper");
}
else if (playerSelection == 'rock' && computerSelection == 'paper') {
losses++;
}
else if (playerSelection == 'paper' && computerSelection == 'scissors') {
losses++;
alert("You lose! Scissors beats Paper")
}
else if (playerSelection == 'scissors' && computerSelection == 'rock') {
losses++;
alert("You lose! Rock beats Scissors");
}
else {
alert("Oops! Something went wrong.");
}
}
function game() {
for(var i = 0; i <=5; i++) {
playRound(playerSelection, computerPlay());
alert("Wins - " + wins + "\n" + "Losses - " + losses + "\n" + "Draws - " + draws);
}
}
game();
</script>
</head>
</html>