-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRockPaperScissors.js
More file actions
52 lines (52 loc) · 1.24 KB
/
RockPaperScissors.js
File metadata and controls
52 lines (52 loc) · 1.24 KB
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
var userChoice = prompt('Do you choose rock, paper or scissors?');
var computerChoice = Math.random();
if (computerChoice < 0.33)
{
computerChoice = 'rock';
}
else if(computerChoice < 0.66)
{
computerChoice = 'paper';
}
else
{
computerChoice = 'scissors';
}
function compare(personChoice , robotChoice)
{
if(personChoice === robotChoice)
{
console.log('Its a Tie!');
}
else if (personChoice === 'rock')
{
if(robotChoice === 'scissors'){
console.log('Rock win!!');
}
else if(personChoice === 'rock'){
console.log('Paper Wins');
}
} else if(personChoice === 'paper'){
if (robotChoice === 'rock'){
console.log('Paper Wins!');
} else if (robotChoice === 'scissors'){
console.log('Scissors Wins!');
}
} else if (personChoice === 'scissors'){
if (robotChoice === 'rock'){
console.log('Rock wins!');
} else if (robotChoice === 'paper'){
console.log('Scissors Wins!');
}
} else if (personChoice === 'bomb'){
if (robotChoice === 'rock'){
console.log('You win!!');
}
else if (robotChoice === 'scissors'){
console.log('You win again!');
} else {
console.log('You win!!!!!!');
}
}
}
compare(userChoice, computerChoice);