-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjavascript.js
43 lines (30 loc) · 1.11 KB
/
javascript.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
const optionBtn = document.querySelectorAll('div.optionBtn button');
let playerScore = 0;
let compScore = 0;
function ComputerPlay() {
const picks = ["rock", "paper", "scissors"];
const ind = Math.floor(Math.random() * picks.length);
return picks[ind]
}
function playRound(e) {
let compSelection = ComputerPlay();
let playerSelection = e.target.textContent;
if ((playerSelection.toLowerCase() == "rock" && compSelection == "scissors") ||
(playerSelection.toLowerCase() == "paper" && compSelection == "rock") ||
(playerSelection.toLowerCase() == "scissors" && compSelection == "paper")) {
playerScore +=1
}
else if (playerSelection.toLowerCase() == compSelection){
playerScore +=0
compScore +=0
}
else {
compScore +=1
}
const player = document.querySelector('.player');
const comp = document.querySelector('.comp');
player.textContent = playerScore;
comp.textContent = compScore;
return playerScore, compScore;
}
optionBtn.forEach(button => button.addEventListener('click', playRound));