-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
43 lines (40 loc) · 1.51 KB
/
index.html
File metadata and controls
43 lines (40 loc) · 1.51 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
<script>
function computerPlay(){
choice = 0;
for(i = 0; i < 2; i++){
choice += Math.round(Math.random())
/* console.log ("Round " + i)
console.log ("choice is " + choice)
*/
}
if (choice == 0) {
console.log ("Computer chose rock");
return "rock"
} else if (choice == 1) {
console.log ("computer chose paper");
return "paper"
} else if (choice == 2) {
console.log ("computer chose scissors");
return "scissors"
}
}
function playRound(playerSelection, computerSelection){
playerchoice = playerSelection.toLowerCase()
if(playerchoice == computerSelection) {
console.log("You tied! You both chose " + playerchoice)
} else if (playerchoice == "rock" && computerSelection == "scissors") {
console.log("You win! You chose " + playerchoice + " and the computer chose " + computerSelection)
} else if (playerchoice == "paper" && computerSelection == "rock") {
console.log("You win! You chose " + playerchoice + " and the computer chose " + computerSelection)
} else if (playerchoice == "scissors" && computerSelection == "paper") {
console.log("You win! You chose " + playerchoice + " and the computer chose " + computerSelection)
} else {
console.log("You lose! You chose " + playerchoice + " and the computer chose " + computerSelection)
}
}
for(i = 0; i < 5; i ++){
answer = prompt("Rock, paper, scissors?")
playRound(answer, computerPlay())
}
</script>
<body></body>