Skip to content
Merged
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
30 changes: 30 additions & 0 deletions Javascript/Rock Paper Scissors/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 🎮 Rock Paper Scissors

A simple browser-based Rock-Paper-Scissors game built with **HTML** and **JavaScript**.

---

## 🧩 Overview

This project allows a user to select **Rock**, **Paper**, or **Scissors**, then plays against the computer.
The computer’s move is chosen randomly, and the result is displayed instantly on the web page.

---

## 💻 How It Works

### 1. HTML Interface
The HTML file (`index.html`) provides:
- A title and instruction header.
- Three radio buttons for selecting your hand.
- A **Submit** button to play.
- A `<div>` element where the result is shown.

```html
<form name="hand">
<input type="radio" name="RPS" value="rock"> Rock<br>
<input type="radio" name="RPS" value="paper"> Paper<br>
<input type="radio" name="RPS" value="scissors"> Scissors<br>
</form>
<input type="button" value="Submit" onclick="game()">
<div id="result"></div>
17 changes: 17 additions & 0 deletions Javascript/Rock Paper Scissors/RPS.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<script src = "RPS.js"></script>
</head>
<body>
<h1>Make your selection</h1>
<form name = "hand">
<input type = "radio" name = "RPS" value = "rock">Rock<br>
<input type = "radio" name = "RPS" value = "paper">Paper<br>
<input type = "radio" name = "RPS" value = "scissors">Scissors<br>
</form>
<br>
<input type = "button" value = "Submit" onclick="game()">
<div id = "result"></div>
</body>
</html>
52 changes: 52 additions & 0 deletions Javascript/Rock Paper Scissors/RPS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
function game(){
randNum = Math.floor(Math.random()*3)
console.log(randNum)
if(hand.RPS[0].checked == true){
you = "rock"
}
else if(hand.RPS[1].checked == true){
you = "paper"
}
else if(hand.RPS[2].checked == true){
you = "scissors"
}
console.log(you)
if(randNum == 0){
randValue = "rock"
}
else if(randNum == 1){
randValue = "paper"
}
else if(randNum == 2){
randValue = "scissors"
}
console.log(randValue)
if(you == randValue){
returnResult= "You and the computer both chose " + you + ", therefore it is a tie";
document.getElementById("result").innerHTML = returnResult
}
else if(you == "rock" && randValue == "paper"){
returnResult = "You chose " + you + ", the computer chose " + randValue + ", so you lose";
document.getElementById("result").innerHTML = returnResult
}
else if(you == "rock" && randValue == "scissors"){
returnResult = "You chose " + you + ", the computer chose " + randValue + ", so you win";
document.getElementById("result").innerHTML = returnResult
}
else if(you == "scissors" && randValue == "rock"){
returnResult = "You chose " + you + ", the computer chose " + randValue + ", so you lose";
document.getElementById("result").innerHTML = returnResult
}
else if(you == "scissors" && randValue == "paper"){
returnResult = "You chose " + you + ", the computer chose " + randValue + ", so you win";
document.getElementById("result").innerHTML = returnResult
}
else if(you == "paper" && randValue == "rock"){
returnResult = "You chose " + you + ", the computer chose " + randValue + ", so you win";
document.getElementById("result").innerHTML = returnResult
}
else if(you == "paper" && randValue == "scissors"){
returnResult= "You chose " + you + ", the computer chose " + randValue + ", so you lose";
document.getElementById("result").innerHTML = returnResult
}
}
Loading