-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
46 lines (41 loc) · 1.7 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
var result = document.getElementById("result");
var userScore = document.getElementById("userScore");
var compScore = document.getElementById("compScore");
var getUserScore = 0;
var getCompScore = 0;
var defaultSelection = ["Rock", "Paper", "Scissors"];
userScore.innerHTML = "0";
compScore.innerHTML = "0";
function getUserChoices(e) {
//get the alt value so that we can compare afterwards
var userChoice = e.alt;
//generate random number from 0~2 to determine the computer choice
var num = Math.floor(Math.random() * defaultSelection.length)
var compChoice = defaultSelection[num];
determinedResult(userChoice, compChoice);
}
function determinedResult(user, comp) {
//concatenate 2 variable strings together for determine winner
var checkWinner = user + comp;
//Use switch statement to see who win the match
switch (checkWinner) {
case "RockScissors":
case "PaperRock":
case "ScissorsPaper":
getUserScore++;
userScore.innerHTML = getUserScore.toString();
result.innerHTML = user + "user".fontsize(3).sub() + " and " + comp + "comp".fontsize(3).sub() + " User Win ! ! !";
break;
case "ScissorsRock":
case "RockPaper":
case "PaperScissors":
getCompScore++;
compScore.innerHTML = getCompScore.toString();
result.innerHTML = user + "user".fontsize(3).sub() + " and " + comp + "comp".fontsize(3).sub() + " Computer Win ! ! !";
break;
case "RockRock":
case "PaperPaper":
case "ScissorsScissors":
result.innerHTML = user + "user".fontsize(3).sub() + " and " + comp + "comp".fontsize(3).sub() + "It's a DRAW ! ! !";
}
}