-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
61 lines (54 loc) · 2.06 KB
/
main.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
const choices = ["rock", "paper", "scissors"];
let playerScore = 0;
let computerScore = 0;
function game() {
//play 5 rounds
//console based
for (let i=0; i<5 ;i++) {
let playerChoice = prompt("Please type in your choice here:", "");
console.log(playRound(playerChoice.toLowerCase(), computerChoice().toLowerCase()));
}
if (playerScore > computerScore) return "You beat the computer! You are a genius!";
else if (playerScore < computerScore) return "You got beat by the computer! Try again!";
else return "You tied! Almost there!";
}
function playRound(playerSelection, computerSelection) {
//one round
if (playerSelection== "rock" && computerSelection == "rock") {
return "You tied! You both picked rock";
} else if (playerSelection== "paper" && computerSelection == "paper") {
return "You tied! You both picked paper";
} else if (playerSelection== "scissors" && computerSelection == "scissors") {
return "You tied! You both picked scissors";
} else if (playerSelection== "scissors" && computerSelection == "rock") {
computerScore++;
return "You lost! Rock crushes scissors";
} else if (playerSelection== "scissors" && computerSelection == "paper") {
playerScore++;
return "You won! Scissors cuts paper";
} else if (playerSelection== "rock" && computerSelection == "paper") {
computerScore++;
return "You lost! Paper covers rock";
} else if (playerSelection== "rock" && computerSelection == "scissors") {
playerScore++;
return "You won! Rock crushes scissors";
} else if (playerSelection== "paper" && computerSelection == "scissors") {
computerScore++;
return "You lost! Scissors cuts paper";
} else if (playerSelection== "paper" && computerSelection == "rock") {
playerScore++;
return "You won! Paper covers rock";
}
}
function playerChoice() {
//get input
}
function computerChoice() {
//get random input from computer
let random_idx = Math.floor(Math.random()*choices.length);
return choices[random_idx];
}
console.log(game());
function refreshPage(){
window.location.reload();
}