-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
72 lines (57 loc) · 1.78 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<script>
function getComputerChoice() {
var a = Math.floor(Math.random() * 3);
if (a == 0) {
return 'rock';
}
else if (a == 1) {
return 'scissors';
}
else {
return 'paper';
}
}
function playRound(playerSelection, computerSelection) {
playerSelection = playerSelection.toLowerCase()
if (playerSelection == 'rock' && computerSelection == 'paper') {
return "You Lose! Paper beats Rock!";
}
else if (playerSelection == 'rock' && computerSelection == 'scissors') {
return "You win! Rock beats Scissors!";
}
else if (playerSelection == 'paper' && computerSelection == 'rock') {
return "You win! Paper beats Rock!";
}
else if (playerSelection == 'paper' && computerSelection == 'scissors') {
return "You Lose! Scissors beats Paper!";
}
else if (playerSelection == 'scissors' && computerSelection == 'paper') {
return "You win! Scissors beats Paper!";
}
else if (playerSelection == 'scissors' && computerSelection == 'rock') {
return "You Lose! Rock beats Scissors!";
}
else {
return "It's a tie!";
}
}
function game() {
const playerSelection = prompt("Enter your selection");
const computerSelection = getComputerChoice()
return playRound(playerSelection, computerSelection);
}
for (var i = 0; i < 5; i++) {
console.log(game());
}
</script>
<body>
test
</body>
</html>