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
39 changes: 39 additions & 0 deletions RPS/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Rock Paper Scissor rps</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css">
</head>
<body>
<div class="container">
<div class="scores">
<p>
You :
<span id="user_score">0</span>
</p>
<p>Computer :
<span id="computer_score">0</span>
</p>
</div>
<div class="buttons">
<button>
<i class="rock far fa-hand-rock"></i>
</button>
<button>
<i class="paper far fa-hand-paper"></i>
</button>
<button>
<i class="scissor far fa-hand-scissors"></i>
</button>
</div>
<div class="info">
<p id="your-choice"></p>
<p id="computer-choice"></p>
<b><p id="result"></p></b>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
61 changes: 61 additions & 0 deletions RPS/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
let your_score = 0;
let computer_score = 0;
let result_ref = document.getElementById("result");
const rock_button = document.querySelector(".rock");
const paper_button = document.querySelector(".paper");
const scissor_button = document.querySelector(".scissor");
const yourOptions = [rock_button, paper_button, scissor_button];

rock_button.addEventListener("click", function () {
rps("rock");
});

paper_button.addEventListener("click", function () {
rps("paper");
});

scissor_button.addEventListener("click", function () {
rps("scissor");
});
yourOptions.forEach((option) => {
option.addEventListener("click", function () { });
});

computer = (computer_choice) => {
computer_options = ["rock", "paper", "scissor"];
number = Math.floor(Math.random() * 3);
computer_choice = computer_options[number];
return computer_choice;
};

rps = (your_choice) => {
const comp_choice = computer();

if (your_choice == comp_choice) {
result_ref.textContent = "Draw";
} else if (
(your_choice == "rock") & (comp_choice == "scissor") ||
(your_choice == "paper") & (comp_choice == "rock") ||
(your_choice == "scissor") & (comp_choice == "paper")
) {
your_score +=1;
your_score.innerText = your_score;
result_ref.textContent = "You Win";
} else if (
(your_choice == "rock") & (comp_choice == "paper") ||
(your_choice == "paper") & (comp_choice == "scissor") ||
(your_choice == "scissor") & (comp_choice == "rock")
) {
computer_score++;
computer_score.innerText = computer_score;
result_ref.textContent = "Computer Win";
}
document.getElementById("computer-choice").innerHTML =
` Computer choose <span> ${comp_choice.toUpperCase()} </span>`;

document.getElementById("your-choice").innerHTML =
` You choose <span> ${your_choice.toUpperCase()} </span>`;

document.getElementById("computer_score").innerHTML = computer_score;
document.getElementById("user_score").innerHTML = your_score;
};
38 changes: 38 additions & 0 deletions RPS/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.container{
width: 45%;
min-width: 500px;
background-color: #ffffff;
padding: 40px 30px;
position: absolute;
transform: translate(-50%,-50%);
top: 50%;
left: 50%;
border-radius: 10px;
box-shadow: 0 15px 25px rgba(0,0,0,0.15);
}
.scores{
margin-bottom: 50px;
text-align: right;
}
.buttons{
width: 90%;
margin: auto;
display: flex;
justify-content: space-around;
}
.buttons button{
background-color: #ffd51b;
color: #000000;
border: none;
font-size: 50px;
height: 100px;
width: 100px;
border-radius: 50%;
}
.info{
margin-top: 30px;
text-align: center;
}
span{
font-weight: 600;
}