-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrockpaperscissors.js
More file actions
49 lines (40 loc) · 1.58 KB
/
rockpaperscissors.js
File metadata and controls
49 lines (40 loc) · 1.58 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
/**
* Created by emddutton on 2/5/2015.
*/
$(document).ready(function() {
var shake = $(".handshake");
var counter = $(".choose h2");
var choices = ["rock", "paper", "scissors"];
var userChoice, compChoice;
function reset(){
$(".computer > .left").hide();
$(".you > .right").hide();
counter.hide();
shake.show();
};
$("button").on('click', function(){
reset();
shake.addClass('shake');
counter.hide();
compChoice = choices[Math.floor(Math.random()*3)];
userChoice = this.id;
console.log(compChoice);
setTimeout(function() {
shake.hide();
$(".computer > .left." + compChoice).show();
$(".you > .right." + userChoice).show();
if(compChoice === userChoice){
counter.show().text("It's a tie!");
console.log("tie");
}
else if((userChoice == 'rock' && compChoice == 'scissors')|| (userChoice == 'scissors' && compChoice == 'paper') || (userChoice == 'paper' && compChoice == 'rock')){
counter.show().text("You win!");
console.log("winner winner chicken dinner");
}
else if((userChoice == 'rock' && compChoice == 'paper') || (userChoice == 'scissors' && compChoice == 'rock') || (userChoice == 'paper' && compChoice == 'scissors') ){
counter.show().text("You lose.");
console.log("loser");
}
}, 1000);
});
});