-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
76 lines (60 loc) · 2.02 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
67
68
69
70
71
72
73
74
75
76
let humanScore = 0;
let computerScore = 0;
function getComputerChoice(){
let number = Math.floor(Math.random() * 3);
if(number === 0) return("rock");
else if(number === 1) return("paper");
else return("scissor");
}
//console.log(getComputerChoice())
function getHumanChoice(){
let sign = prompt("Choose rock, paper or scissor?");
return sign
}
//console.log(getHumanChoice())
function playRound( ComputerChoice, HumanChoice ){
if (ComputerChoice === HumanChoice.toLowerCase()){
console.log("Draw! Play again");
}
else if (ComputerChoice == "rock" && HumanChoice.toLowerCase() == "paper" ){
humanScore = humanScore + 1;
console.log("You won! Paper beats Rock")
}
else if (ComputerChoice == "rock" && HumanChoice.toLowerCase() == "scissor" ){
computerScore = computerScore + 1;
console.log("You lose! Rock beats Scissor")
}
else if (ComputerChoice == "paper" && HumanChoice.toLowerCase() == "rock" ){
computerScore = computerScore + 1;
console.log("You lost! Paper beats Rock")
}
else if (ComputerChoice == "paper" && HumanChoice.toLowerCase() == "scissor" ){
humanScore = humanScore + 1;
console.log("You won! Scissor beats Paper")
}
else if (ComputerChoice == "scissor" && HumanChoice.toLowerCase() == "paper" ){
computerScore = computerScore + 1;
console.log("You lost! Scissor beats Paper")
}
else if (ComputerChoice == "scissor" && HumanChoice.toLowerCase() == "rock" ){
humanScore = humanScore + 1;
console.log("You won! Rock beats Scissor")
}
else {
console.log("Invalid input")
}
}
function playGame(){
for(i=0; i<5; i++){
const computerSelection = getComputerChoice();
const humanSelection = getHumanChoice();
playRound(computerSelection, humanSelection);
}
if(computerScore > humanScore){
console.log("Computer won")
}
else { console.log("Human won")
}
console.log(humanScore)
}
playGame()