-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfile.js
54 lines (42 loc) · 1.81 KB
/
file.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
44
45
46
47
48
49
50
51
function playGame() {
let playerScore = 0;
let cpuScore = 0;
let computerSelection;
let playerSelection;
for (let i = 0; i < 3; i++) {
function computerPlay () {
let compOptions = ["rock", "paper", "scissors"];
let randomAnswer = compOptions[Math.floor(Math.random()*compOptions.length)];
return randomAnswer;
};
computerSelection = computerPlay();
function playerPlay() {
do {
var playerOptions = prompt("Type either 'rock', 'paper', or 'scissors' to play").toLowerCase();
} while (playerOptions !== "rock" && playerOptions !== "paper" && playerOptions !== "scissors");
return playerOptions;
};
playerSelection = playerPlay();
function roundWinner() {
if (playerSelection === computerSelection) {
console.log("It's a Tie!");
} else if (
(playerSelection == "rock" && computerSelection == "scissors") ||
(playerSelection == "scissors" && computerSelection == "paper") ||
(playerSelection == "paper" && computerSelection == "rock")
) {
console.log("You Win!");
playerScore = ++playerScore;
} else if (
(playerSelection == "scissors" && computerSelection == "rock") ||
(playerSelection == "paper" && computerSelection == "scissors") ||
(playerSelection == "rock" && computerSelection == "paper")
) {
console.log("You Lose :(");
cpuScore = ++cpuScore;
}
} roundWinner();
} console.log("GAME OVER");
console.log("Player final score:", playerScore);
console.log("PC final score:", cpuScore);
} playGame();