-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrps.html
More file actions
76 lines (59 loc) · 2.32 KB
/
Copy pathrps.html
File metadata and controls
76 lines (59 loc) · 2.32 KB
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>The HTML5 Herald</title>
<meta name="description" content="The HTML5 Herald">
<meta name="author" content="SitePoint">
<link rel="stylesheet" href="css/styles.css?v=1.0">
</head>
<body>
<script>
let playerScore = 0;
let computerScore = 0;
function choiceGenerator(){
let choices = ["paper","rock","scissors"]
let randomChoice = choices[Math.floor(Math.random()*choices.length)]
return randomChoice;
}
function playRound(playerSelection,computerSelection){
computerSelection = choiceGenerator();
playerSelection = prompt("make your choice!").toLowerCase();
if (playerSelection == computerSelection) {
return ("it's a tie!");
} else if (playerSelection == "rock" && computerSelection == "scissor"){
playerscore = playerscore + 1
console.log("You win!");
} else if (playerSelection == "rock" && computerSelection == "paper"){
computerScore = computerScore + 1
console.log("You lose!");
} else if (playerSelection == "paper" && computerSelection == "rock"){
playerSelection = playerSelection + 1
console.log("You win!");
} else if (playerSelection == "paper" && computerSelection == "scissors"){
computerScore = computerScore + 1
console.log("You lose!");
} else if (playerSelection == "scissors" && computerSelection == "rock"){
computerScore = computerScore + 1
console.log("You lose!");
} else if (playerSelection == "scissors" && computerSelection == "paper"){
playerScore = playerScore + 1
console.log("You win!");
}
}
function Game(){
for (i = 0; i < 5; i++)
console.log(playRound());
if (computerScore > playerScore) {
console.log("You lose! Your opponent scored " + computerScore +" and you had "+playerScore);
}
else if (playerScore > computerScore){
console.log("You win! Your score was "+playerScore+" and the computer scored "+ computerScore);
}
else {
return "it's a tie";
}
}
</script>
</body>
</html>