-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
66 lines (59 loc) · 1.74 KB
/
script.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const rpsOptions = ["rock", "paper", "scissors"];
let humanScore = 0;
let computerScore = 0;
function getComputerChoice () {
choice = Math.round((Math.random() * 2), 0);
return rpsOptions[choice];
}
function getUserChoice () {
choice = prompt("Rock, Paper, Scissors: ");
confirmChoice = rpsOptions.includes(choice.toLowerCase());
if (confirmChoice) {
return choice.toLowerCase();
} else {
alert("Unknown Option!");
}
}
function playRound (humanChoice, computerChoice) {
if (computerChoice === humanChoice) {
console.log("It's a tie!");
}
if (humanChoice === "rock") {
if (computerChoice === "paper") {
console.log("You lose! Paper beats Rock!");
++computerScore;
}
if (computerChoice === "scissors") {
console.log("You win! Rock beats Scissors");
++humanScore;
}
}
if (humanChoice === "paper") {
if (computerChoice === "scissors") {
console.log("You lose! Scissors beats Paper");
++computerScore;
}
if (computerChoice === "rock") {
console.log("You win! Paper beats Rock");
++humanScore;
}
}
if (humanChoice === "scissors") {
if (computerChoice === "rock") {
console.log("You lose! Rock beats Scissors");
++computerScore;
}
if (computerChoice === "paper") {
console.log("You win! Scissors beats Paper");
++humanScore;
}
}
}
function playGame () {
const humanSelection = getUserChoice();
const computerSelection = getComputerChoice();
playRound(humanSelection, computerSelection);
}
for (let num = 0; num < 5; num++) {
playGame()
}