-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
73 lines (67 loc) · 4.18 KB
/
scripts.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
const userRock = document.getElementById('rock');
const userScissors = document.getElementById('scissors');
const userPaper = document.getElementById('paper');
const userLizard = document.getElementById('lizard');
const userSpock = document.getElementById('spock');
const results = document.querySelector('.results')
let choices = ['rock', 'paper', 'scissors', 'lizard', 'spock']
const randomMove = () => {
return choices[Math.floor(Math.random()*choices.length)]
}
let computerMove = randomMove();
let userMove;
const gameLogic = (userMove) => {
if (computerMove === userMove){
results.innerText = 'Tie!'
}else if(computerMove === 'rock' && userMove === 'paper'){
results.innerText = `You win! Computer chose ${computerMove} and user chose ${userMove}`
}else if(computerMove === 'paper' && userMove === 'rock'){
results.innerText = `You lose! Computer chose ${computerMove} and user chose ${userMove}`
}else if(computerMove === 'paper' && userMove === 'scissors'){
results.innerText = `You win! Computer chose ${computerMove} and user chose ${userMove}`
}else if(computerMove === 'scissors' && userMove === 'paper'){
results.innerText = `You win! Computer chose ${computerMove} and user chose ${userMove}`
}else if(computerMove === 'rock' && userMove === 'scissors'){
results.innerText = `You lose! Computer chose ${computerMove} and user chose ${userMove}`
}else if(computerMove === 'scissors' && userMove === 'rock'){
results.innerText = `You win Computer chose ${computerMove} and user chose ${userMove}`
}else if(computerMove === 'lizard' && userMove === 'rock'){
results.innerText = `You win! Computer chose ${computerMove} and user chose ${userMove}`
}else if(computerMove === 'rock' && userMove === 'lizard'){
results.innerText = `You lose! Computer chose ${computerMove} and user chose ${userMove}`
}else if(computerMove === 'lizard' && userMove === 'spock'){
results.innerText = `You lose! Computer chose ${computerMove} and user chose ${userMove}`
}else if(computerMove === 'spock' && userMove === 'lizard'){
results.innerText = `You win! Computer chose ${computerMove} and user chose ${userMove}`
}else if(computerMove === 'scissors' && userMove === 'spock'){
results.innerText = `You win! Computer chose ${computerMove} and user chose ${userMove}`
}else if(computerMove === 'spock' && userMove === 'scissors'){
results.innerText = `You lose! Computer chose ${computerMove} and user chose ${userMove}`
}else if(computerMove === 'scissors' && userMove === 'lizard'){
results.innerText = `You lose! Computer chose ${computerMove} and user chose ${userMove}`
}else if(computerMove === 'lizard' && userMove === 'scissors'){
results.innerText = `You win! Computer chose ${computerMove} and user chose ${userMove}`
}else if(computerMove === 'lizard' && userMove === 'paper'){
results.innerText = `You lose! Computer chose ${computerMove} and user chose ${userMove}`
}else if(computerMove === 'paper' && userMove === 'lizard'){
results.innerText = `You win! Computer chose ${computerMove} and user chose ${userMove}`
}else if(computerMove === 'paper' && userMove === 'spock'){
results.innerText = `You lose! Computer chose ${computerMove} and user chose ${userMove}`
}else if(computerMove === 'spock' && userMove === 'paper'){
results.innerText = `You win! Computer chose ${computerMove} and user chose ${userMove}`
}else if(computerMove === 'rock' && userMove === 'spock'){
results.innerText = `You win! Computer chose ${computerMove} and user chose ${userMove}`
}else if(computerMove === 'spock' && userMove === 'rock'){
results.innerText = `You lose! Computer chose ${computerMove} and user chose ${userMove}`
}
};
userRock.addEventListener('click', function(){
gameLogic('rock')})
userScissors.addEventListener('click', function(){
gameLogic('scissors')});
userPaper.addEventListener('click', function(){
gameLogic('paper')});
userLizard.addEventListener('click', function(){
gameLogic('lizard')});
userSpock.addEventListener('click', function(){
gameLogic('spock')});