-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
75 lines (65 loc) · 2.24 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
const handOptions = {
'rock': "/rockPaperScissors/images/rock.png",
'paper': "/rockPaperScissors/images/paper.png",
'scissors': "/rockPaperScissors/images/scissors.png"
}
let SCORE = 0
const pickUserHand = (hand) => {
let hands = document.querySelector('.hands');
hands.style.display = 'none';
let contest = document.querySelector('.contest');
contest.style.display = 'flex';
document.getElementById('userPickImage').src = handOptions[hand];
let cpHands = pickComputerHand();
referee(hand, cpHands)
}
const pickComputerHand = () => {
let hands = ['rock','paper','scissors']
let cpHands = hands[Math.floor(Math.random() * 3)]
document.getElementById('computerPickImage').src = handOptions[cpHands];
return cpHands
}
const referee = (userHand, cpHands) => {
if(userHand == 'paper' && cpHands == 'scissors'){
setDecision('YOU LOSE')
} else if(userHand == 'paper' && cpHands == 'rock'){
setDecision('YOU WIN')
setScore(SCORE + 1);
}
if(userHand == 'paper' && cpHands == 'paper'){
setDecision("it's a tie")
}
if(userHand == 'rock' && cpHands == 'scissors'){
setDecision('YOU WIN')
setScore(SCORE + 1);
}
if(userHand == 'rock' && cpHands == 'paper'){
setDecision('YOU LOSE')
}
if(userHand == 'rock' && cpHands == 'rock'){
setDecision('it"s a tie')
}
if(userHand == 'scissors' && cpHands == 'scissors'){
setDecision('it"s a tie')
}
if(userHand == 'scissors' && cpHands == 'rock'){
setDecision('YOU LOSE')
}
if(userHand == 'scissors' && cpHands == 'paper'){
setDecision('YOU WIN')
setScore(SCORE + 1);
}
}
const restartGame = () => {
let hands = document.querySelector('.hands');
hands.style.display = 'flex';
let contest = document.querySelector('.contest');
contest.style.display = 'none';
}
const setDecision = (decision) => {
document.querySelector('.decision h1').innerText = decision;
}
const setScore = (score) =>{
SCORE = score;
document.querySelector('.score h1').innerText = score;
}