-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
71 lines (69 loc) · 2.31 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
const computerChoiceDisplay = document.getElementById("computer-choice");
let computerChoice;
var idk = Math.floor(Math.random()*3+1);
if(idk===1){
computerChoice = "rock";
}
else if(idk===2){
computerChoice = "paper";
}
else if(idk===3){
computerChoice = "scissors";
}
let userChoice;
// When the user clicks on a button
$(".start-button").click(function(){
$("#computer-choice-"+computerChoice).css("visibility","visible")
$(".comp-heading").css("visibility","visible")
$(".temp").text("You Chose:")
userChoice=this.id;
$("#"+userChoice).addClass("shadow-effect")
if(userChoice==="rock"){
$("#paper").addClass("disabled")
$("#scissors").addClass("disabled")
$(".start-button").removeClass("hover-effect")
}
else if(userChoice==="paper"){
$("#rock").addClass("disabled")
$("#scissors").addClass("disabled")
$(".start-button").removeClass("hover-effect")
}
else if(userChoice==="scissors"){
$("#paper").addClass("disabled")
$("#rock").addClass("disabled")
$(".start-button").removeClass("hover-effect")
}
if(userChoice===computerChoice){
$("#main-title").text("It's a Draw! (¬_¬)");
playSound("draw")
}
else if(userChoice==="rock" && computerChoice==="paper"){
$("#main-title").text("You Lost! (╯°□°)╯");
playSound("lose")
}
else if(userChoice==="rock" && computerChoice==="scissors"){
$("#main-title").text("You Won!└(^o^ )X( ^o^)┘");
playSound("win")
}
else if(userChoice==="scissors" && computerChoice==="paper"){
$("#main-title").text("You Won!└(^o^ )X( ^o^)┘");
playSound("win")
}
else if(userChoice==="scissors" && computerChoice==="rock"){
$("#main-title").text("You Lost! (╯°□°)╯");
playSound("lose")
}
else if(userChoice==="paper" && computerChoice==="rock"){
$("#main-title").text("You Won!└(^o^ )X( ^o^)┘");
playSound("win")
}
else if(userChoice==="paper" && computerChoice==="scissors"){
$("#main-title").text("You Lost! (╯°□°)╯");
playSound("lose")
}
$(".restart").text("Please refresh to play again :)")
})
function playSound(name){
var audio = new Audio("sounds/" + name + ".wav");
audio.play();
}