-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.js
59 lines (55 loc) · 1.28 KB
/
app.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
let userScore = 0;
let computerScore = 0;
let userChoice = "";
function getComputerChoice()
{
const choices = ["R", "P", 'S'];
let arrayIndex = Math.floor(Math.random() * 3);
return choices[arrayIndex];
}
function game(userChoice)
{
let computerChoice = getComputerChoice();
console.log(userChoice + computerChoice)
switch(userChoice + computerChoice)
{
case "PR":
case "SP":
case "RS":
userScore++;
console.log('USER WINS');
//innerHTML adjustment
break;
case "PS":
case "SR":
case "RP":
computerScore++;
console.log("COMPUTER WINS");
//innerHTML adjustment
break;
case "PP":
case "SS":
case "RR":
console.log("It's a tie");
//innerHTML adjustment
break;
}
}
rock.addEventListener("click", function()
{
userChoice = "R";
game(userChoice);
//console.log("Testing the R button");
});
paper.addEventListener("click", function()
{
userChoice = "P";
game(userChoice);
//console.log("Testing the P button");
});
scissors.addEventListener("click", function()
{
userChoice = "S";
game(userChoice);
//console.log("Testing the S button");
});