Skip to content

Commit 4ea1654

Browse files
basic rock paper scissors game
1 parent 799303a commit 4ea1654

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
let player,cpu;
2+
3+
4+
5+
document.getElementById("rock").addEventListener("click", () => simulate("rock"));
6+
document.getElementById("paper").addEventListener("click", () => simulate("paper"));
7+
document.getElementById("scissors").addEventListener("click", () => simulate("scissors"));
8+
9+
10+
function simulate(player){
11+
cpu_choices = ["rock","paper","scissors"];
12+
13+
random_element = Math.floor(Math.random() * 3);
14+
cpu = cpu_choices[random_element];
15+
16+
console.log(cpu);
17+
18+
if (player == "rock"){
19+
if (cpu == "scissors"){
20+
document.getElementById("outcome").textContent = "OUTCOME: Player Wins";
21+
document.getElementById("choices").textContent = "ROCK BEATS SCISSORS";
22+
}
23+
if (cpu == "paper"){
24+
document.getElementById("outcome").textContent = "OUTCOME: Computer Wins";
25+
document.getElementById("choices").textContent = "PAPER BEATS ROCK";
26+
}
27+
if (cpu == "rock") {
28+
document.getElementById("outcome").textContent = "OUTCOME: Tie";
29+
document.getElementById("choices").textContent = "YOU BOTH PICKED ROCK";
30+
}
31+
}
32+
if (player == "scissors"){
33+
if (cpu == "rock"){
34+
document.getElementById("outcome").textContent = "OUTCOME: Computer Wins";
35+
document.getElementById("choices").textContent = "ROCK BEATS SCISSORS";
36+
}
37+
if (cpu == "paper"){
38+
document.getElementById("outcome").textContent = "OUTCOME: Player Wins";
39+
document.getElementById("choices").textContent = "SCISSORS BEATS PAPER";
40+
}
41+
if (cpu == "scissors"){
42+
document.getElementById("outcome").textContent = "OUTCOME: Tie";
43+
document.getElementById("choices").textContent = "YOU BOTH PICKED SCISSORS";
44+
}
45+
}
46+
if (player == "paper"){ // player is paper
47+
if (cpu == "rock"){
48+
document.getElementById("outcome").textContent = "OUTCOME: Player Wins";
49+
document.getElementById("choices").textContent = "PAPER BEATS ROCK";
50+
}
51+
if (cpu == "scissors"){
52+
document.getElementById("outcome").textContent = "OUTCOME: Computer Wins";
53+
document.getElementById("choices").textContent = "SCISSORS BEATS PAPER";
54+
}
55+
if (cpu == "paper"){
56+
document.getElementById("outcome").textContent = "OUTCOME: Tie";
57+
document.getElementById("choices").textContent = "YOU BOTH PICKED PAPER";
58+
}
59+
}
60+
61+
}

students/tylerarc/rps.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Rock Paper Scissors Game</title>
7+
</head>
8+
<body>
9+
<h1>Play Rock Paper Scissors Against the Computer!</h1>
10+
11+
<button id = "rock">ROCK</button>
12+
<button id = "paper">PAPER</button>
13+
<button id = "scissors">SCISSORS</button>
14+
15+
<br>
16+
<p id = "outcome">OUTCOME:
17+
18+
</p>
19+
<br>
20+
<p1 id = "choices"></p1>
21+
22+
23+
24+
</body>
25+
<script src = "rock_paper_scissors.js"></script>
26+
</html>

0 commit comments

Comments
 (0)