-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRockPaperScissor.js
44 lines (39 loc) · 1.29 KB
/
RockPaperScissor.js
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
let score = 0
function getComputerChoice() {
let Choices = ["rock", "paper", "scissor"]
return Choices[parseInt(Math.random() * 3)]
}
function playRound(playerSelection, computerSelection) {
if (playerSelection.toLowerCase() === computerSelection) {
return `It's a Tie!`
} else if (
playerSelection.toLowerCase() === "rock" &&
computerSelection === "paper"
) {
score -= 1
return `You LOST! ${computerSelection} beats ${playerSelection}`
} else if (
playerSelection.toLowerCase() === "paper" &&
computerSelection === "scissor"
) {
score -= 1
return `You LOST! ${computerSelection} beats ${playerSelection}`
} else if (
playerSelection.toLowerCase() === "scissor" &&
computerSelection === "rock"
) {
score -= 1
return `You LOST! ${computerSelection} beats ${playerSelection}`
} else {
score += 1
return `You WON! ${playerSelection} beats ${computerSelection}`
}
}
function game() {
for (let i = 1; i <= 5; i++) {
let playerSelection = prompt("Enter your choice (rock, paper, scisser)")
alert(playRound(playerSelection, getComputerChoice()))
}
alert(score >= 3 ? "Congrats You WON!" : "You SUCK at this GAME")
}
console.log(game())