-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaper-scissors-rock-bang.js
60 lines (51 loc) · 1.5 KB
/
paper-scissors-rock-bang.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
const getUserChoice = userInput => {
userInput = userInput.toLowerCase()
if (userInput === 'bang' || userInput === 'rock' || userInput === 'paper' || userInput === 'scissors'){
return (userInput)
} else {
console.log('Please enter rock, paper or scissors');
}
};
userFinal = getUserChoice('paper')
const getComputerChoice= () => {
computerChoice = Math.floor(Math.random()*3)
if (computerChoice === 0) {
return 'rock';
} else if (computerChoice === 1){
return 'paper';
} else if (computerChoice === 2){
return 'scissors'
} else { console.log('broken')}
}
computerFinal = getComputerChoice();
const determineWinner = (userFinal, computerFinal) => {
if(userFinal === 'bang'){
console.log('User has chosen the nuclear option: User WINS!')
}else if(userFinal === computerFinal){
console.log('It was a tie!')
} else if(userFinal === 'rock'){
if(computerFinal === 'paper'){
console.log('Computer wins!')
} else {
console.log('User wins!')
}
} else if(userFinal === 'paper'){
if (computerFinal === 'scissors'){
console.log('Computer wins!')
} else {
console.log('User wins!')
}
} else if (userFinal === 'scissors'){
if (computerFinal === 'paper') {
console.log('User wins!')
} else {
console.log('Computer wins!')
}
}
}
function playGame(){
console.log(`User chose: ` + userFinal)
console.log(`Computer chose: `+ computerFinal);
determineWinner(userFinal, computerFinal)
}
playGame()