Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions rps_game/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rock Paper Scissors</title>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>

<body>
<h1>Opponent Score</h1>
<h1 id="opponent-score">0</h1>
<img id="opponent-choice">
<br>
<img id="your-choice">
<div id="choices">
</div>
<h1 id="your-score">0</h1>
<h1>User Score</h1>

</body>
</html>
Binary file added rps_game/paper.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rps_game/rock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rps_game/scissors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions rps_game/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
let you;
let yourScore = 0;
let opponent;
let opponentScore = 0;

let choices = ["rock", "paper", "scissors"];

window.onload = function() {
for (let i = 0; i < 3; i++) {
let choice = document.createElement("img");
choice.id = choices[i];
choice.src = choices[i] + ".png";
choice.addEventListener("click", selectChoice);
document.getElementById("choices").append(choice);
}
}

function selectChoice() {
you = this.id;
document.getElementById("your-choice").src = you + ".png";

//random for oppponent
opponent = choices[Math.floor(Math.random() * 3)];
document.getElementById("opponent-choice").src = opponent + ".png";

//check for winner
let user_win = ( (you === "rock") && (opponent === "scissors") ||
(you === "paper") && (opponent === "rock") ||
(you === "scissors") && (opponent === "paper"))


let computer_win = ( (opponent === "rock") && (you === "scissors") ||
(opponent === "paper") && (you === "rock") ||
(opponent === "scissors") && (you === "rock") )

user_win ? alert('yuppie😀 you got a point') : computer_win ? alert('shit😣 opponent got a point') : alert('Its a tie')

scoreincrement(user_win,computer_win)
document.getElementById("your-score").innerText = yourScore;
document.getElementById("opponent-score").innerText = opponentScore;
}

const scoreincrement = (user,computer_win)=>{
return user ? yourScore += 1 : computer_win ? opponentScore +=1 : ""
}
27 changes: 27 additions & 0 deletions rps_game/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
body{
font-family: Arial, Helvetica, sans-serif;
text-align: center;
background-color: blanchedalmond;
}
#opponent-choice{
width: 240px;
height: 240px;
margin-top: 10px;

}
#your-choice{
width: 240px;
height: 240px;
margin-top: 10px;

}
#choices{
width: 240px;
height: 80px;
margin-top: 10px;
margin: 0 auto;
}
#choices img{
width: 80px;
height: 80px;
}