-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
executable file
·50 lines (50 loc) · 1.7 KB
/
app.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
function playWithMe() {
event.preventDefault();
let userChoice = prompt("Challenge accepted 😉. Pick your choice: rock, paper, scissors");
userChoice = userChoice.toLowerCase();
userChoice = userChoice.trim();
let options = ["rock", "paper", "scissors"];
if (!options.includes(userChoice)) {
alert("That's not a valid choice... Are you getting cold feet? 😇");
} else {
let myChoice = Math.random();
if (myChoice < 0.34) {
myChoice = "rock";
} else if (myChoice <= 0.67) {
myChoice = "paper";
} else {
myChoice = "scissors";
}
compare(userChoice, myChoice);
}
};
function compare(choice1, choice2) {
event.preventDefault();
if (choice1 === choice2) {
alert("It's a tie! We are both pretty good at this 🙌🏽");
} else {
if (choice1 === "rock") {
if (choice2 === "scissors") {
alert("Rock wins! You are good! 🤓");
} else {
alert("Paper wins! Try again! You might win next time 😛");
}
}
if (choice1 === "paper") {
if (choice2 === "rock") {
alert("Paper wins! You are good! 🤓");
} else {
alert("Scissors win! Try again! You might win next time 😛");
}
}
if (choice1 === "scissors") {
if (choice2 === "paper") {
alert("Scissors win! You are good! 🤓");
} else {
alert("Rock wins! Try again! You might win next time 😛");
}
}
}
}
let game = document.getElementById("challenge");
game.addEventListener("click", playWithMe);