-
Notifications
You must be signed in to change notification settings - Fork 0
/
rock_paper_scissors.js
41 lines (39 loc) · 1.76 KB
/
rock_paper_scissors.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
// const playerSelection = prompt("enter a name").toLowerCase();
const gameChoices = ["rock", "paper", "scissors"];
const playerSelection = prompt(
"enter a name ;either rock,paper or scissors"
).toLowerCase();
const getComputerChoice =
gameChoices[Math.floor(Math.random() * gameChoices.length)];
console.log(getComputerChoice);
function playRound(playerSelection, getComputerChoice) {
if (playerSelection === getComputerChoice) {
console.log(
`computer and player tied :They both chose ${getComputerChoice}`
);
} else if (playerSelection === scissors && getComputerChoice === paper) {
console.log(
`player beats computer because player chose ${playerSelection} and computer chose ${getComputerChoice}`
);
} else if (playerSelection === paper && getComputerChoice === rock) {
console.log(
`player beats computer because player chose ${playerSelection} and computer chose ${getComputerChoice}`
);
} else if (playerSelection === rock && getComputerChoice === scissors) {
console.log(
`player beats computer because player chose ${playerSelection} and computer chose ${getComputerChoice}`
);
} else if (getComputerChoice === scissors && getComputerChoice === paper) {
console.log(
`computer beats computer because player chose ${getComputerChoice} and computer chose ${playerSelection}`
);
} else if (getComputerChoice === paper && getComputerChoice === rock) {
console.log(
`computer beats computer because player chose ${getComputerChoice} and computer chose ${playerSelection}`
);
} else if (getComputerChoice === rock && getComputerChoice === scissors) {
console.log(
`computer beats computer because player chose ${getComputerChoice} and computer chose ${playerSelection}`
);
}
}