-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
40 lines (36 loc) · 1.2 KB
/
main.js
File metadata and controls
40 lines (36 loc) · 1.2 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
function rpsls(){
let random = Math.random()
if (random >.20) {
return "rock"
} else if (random > .4){
return "paper"
} else if (random > .6){
return "scissors"
} else if (random > .8) {
return "lizard"
} else {
return "spock"
}
}
function checkWin(choice){
let botChoice = rpsls()
if((choice === "paper" && botChoice === "rock") || (choice === "scissors" && botChoice === "paper") || (choice === "rock" && botChoice === "scissors") || (choice === "spock" && botChoice === "rock") || (choice === "spock" && botChoice === "scissors") || (choice === "lizard" && botChoice === "paper") || (choice === "lizard" && botChoice === "spock") || (choice === "scissors" && botChoice === "lizard") || (choice === "paper" && botChoice === "spock") || (choice === "rock" && botChoice === "lizard")){
console.log("you won!")
}else if(choice === botChoice){
console.log("tie")
}else {
console.log('lose')
}
}
checkWin("paper")
checkWin("spock")
checkWin("lizard")
checkWin("paper")
checkWin("spock")
checkWin("lizard")
checkWin("paper")
checkWin("spock")
checkWin("lizard")
checkWin("paper")
checkWin("spock")
checkWin("lizard")