-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
81 lines (67 loc) · 2.21 KB
/
index.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
77
78
79
80
81
const computerGuess = document.getElementById("computer-guess")
const playerGuess = document.getElementById("player-guess")
const btn = document.querySelectorAll("button")
const playerScoreEl = document.getElementById("playerScore")
const computerScoreEl = document.getElementById("computerScore")
let playerScoreVal = 0
let computerScoreVal = 0
let computerTry
let playerTry
function rock() {
playerGuess.textContent = "Rock"
playerTry = "Rock"
createComputerChoice()
}
function paper() {
playerGuess.textContent = "Paper"
playerTry = "Paper"
createComputerChoice()
}
function scissors() {
playerGuess.textContent = "Scissors"
playerTry = "Scissors"
createComputerChoice()
}
function createComputerChoice() {
const randomNumber = Math.floor(Math.random() * 3 + 1)
if (randomNumber === 1) {
computerTry = "Rock"
}
if (randomNumber === 2) {
computerTry = "Paper"
}
if (randomNumber === 3) {
computerTry = "Scissors"
}
computerGuess.textContent = computerTry
if (playerTry === computerTry) {
null
} if (playerTry === "Rock" && computerTry === "Scissors") {
playerScoreEl.textContent = playerScoreVal += 1
glow()
} if (playerTry === "Rock" && computerTry === "Paper") {
computerScoreEl.textContent = computerScoreVal += 1
glow()
} if (playerTry === "Paper" && computerTry === "Rock" ) {
playerScoreEl.textContent = playerScoreVal += 1
glow()
} if (playerTry === "Paper" && computerTry === "Scissors" ) {
computerScoreEl.textContent = computerScoreVal += 1
glow()
} if (playerTry === "Scissors" && computerTry === "Rock" ) {
computerScoreEl.textContent = computerScoreVal += 1
glow()
} if (playerTry === "Scissors" && computerTry === "Paper" ) {
playerScoreEl.textContent = playerScoreVal += 1
glow()
}
}
function glow() {
if (playerScoreVal > computerScoreVal) {
playerScoreEl.style.backgroundColor = "#6BF178";
computerScoreEl.style.backgroundColor = "#080001";
} else {
playerScoreEl.style.backgroundColor = "#080001";
computerScoreEl.style.backgroundColor = "#6BF178";
}
}