-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoriginal.html
55 lines (49 loc) · 1.53 KB
/
original.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
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<meta charset="UTF-8"/>
</head>
<body>
<script>
// Your JavaScript goes here!
const computerSelection = computerPlay();
let playerScore = 0;
let computerScore = 0;
function playRound() {
computerPlay();
let playerSelection = prompt('Rock paper scissors?', '');
if ((computerSelection == 'rock' && playerSelection == 'scissors') || (computerSelection == 'scissors' && playerSelection == 'paper') || (computerSelection == 'paper' && playerSelection == 'rock')) {
computerScore += 1;
console.log(playerScore, computerScore);
return "You lost.";
} else if (computerSelection == playerSelection) {
console.log(playerScore, computerScore);
return "Tie game.";
} else {
playerScore += 1;
console.log(playerScore, computerScore);
return "You won!";
}
}
function computerPlay() {
let options = ['rock', 'paper', 'scissors'];
let choice = options[Math.floor(Math.random() * options.length)];
return choice;
}
function game() {
for (i = 0; i < 5; i++) {
playRound();
}
console.log(playerScore, computerScore);
if (computerScore > playerScore) {
return "You lost.";
} else if (computerScore == playerScore) {
return "Tie game.";
} else {
return "You won!";
}
}
</script>
</body>
</html>