-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
130 lines (111 loc) · 4.14 KB
/
Copy pathscript.js
File metadata and controls
130 lines (111 loc) · 4.14 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
let playerSelection
let icons = document.querySelector('.icons');
icons.addEventListener('click', (x) => {
switch(x.target.id) {
case 'rock':
playerSelection = "rock";
matchEvaluation(playerSelection);
break;
case 'paper':
playerSelection = "paper";
matchEvaluation(playerSelection);
break;
case 'scissors':
playerSelection = "scissors";
matchEvaluation(playerSelection);
break;
};
});
function matchEvaluation(playerSelection) {
let possibleSelections = ["rock", "paper", "scissors"];
let computerSelection = possibleSelections[Math.floor(Math.random() * possibleSelections.length)];
let yourChoice = document.querySelector('#yourChoice');
yourChoice.textContent = playerSelection;
let opponentChoice = document.querySelector('#opponentChoice');
opponentChoice.textContent = computerSelection;
let matchOutcome = document.querySelector('#matchOutcome');
if (computerSelection == "rock") {
if (playerSelection == "rock") {
matchOutcome.textContent = "It's a tie! C'mon, try again!";
}
else if (playerSelection == "paper") {
matchOutcome.textContent = 'You won! Lucky you!';
winCounter = increment(winCounter);
displayWinCounter.textContent = winCounter
scoreStatus();
return winCounter;
}
else if (playerSelection == "scissors") {
matchOutcome.textContent = "You lost. Better luck next time :'(";
loseCounter = increment(loseCounter);
displayLoseCounter.textContent = loseCounter
scoreStatus();
return loseCounter
}
else {
alert("Invalid entry. You can chose between Rock, Paper or Scissors.");
}
}
else if (computerSelection == "paper") {
if (playerSelection =="rock") {
matchOutcome.textContent = "You lost. Better luck next time :'(";
loseCounter = increment(loseCounter);
displayLoseCounter.textContent = loseCounter
scoreStatus();
return loseCounter
}
else if (playerSelection == "paper") {
matchOutcome.textContent = "It's a tie! C'mon, try again!";
}
else if (playerSelection == "scissors") {
matchOutcome.textContent = "You won! Lucky you!";
winCounter = increment(winCounter);
displayWinCounter.textContent = winCounter
scoreStatus();
return winCounter;
}
else {
alert("Invalid entry. You can chose between Rock, Paper or Scissors.")
}
}
else if (computerSelection == "scissors"){
if (playerSelection == "rock") {
matchOutcome.textContent = "You won! You rock!!!";
winCounter = increment(winCounter);
displayWinCounter.textContent = winCounter
scoreStatus();
return winCounter;
}
else if (playerSelection == "paper") {
matchOutcome.textContent = "You lost. Better luck next time :'(";
loseCounter = increment(loseCounter);
displayLoseCounter.textContent = loseCounter
scoreStatus();
return loseCounter
}
else if (playerSelection == "scissors") {
matchOutcome.textContent = "It's a tie! C'mon, try again!";
}
else {
alert("Invalid entry. You can chose between Rock, Paper or Scissors.")
}
}
};
let winCounter = 0
let loseCounter = 0
function scoreStatus() {
if(winCounter == 5) {
if(alert("You won the game!!! Want to play again?")){}
else window.location.reload();
}
else if(loseCounter == 5) {
if(alert("You lost the game. Want the rematch?")){}
else window.location.reload();
}
};
let displayWinCounter = document.querySelector('#displayWinCounter');
let displayLoseCounter = document.querySelector('#displayLoseCounter');
function increment(counter) {
counter = ++counter;
return counter;
};