diff --git a/Javascript/Rock Paper Scissors/README.md b/Javascript/Rock Paper Scissors/README.md new file mode 100644 index 0000000..cd375cd --- /dev/null +++ b/Javascript/Rock Paper Scissors/README.md @@ -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 `
` element where the result is shown. + +```html +
+ Rock
+ Paper
+ Scissors
+
+ +
diff --git a/Javascript/Rock Paper Scissors/RPS.html b/Javascript/Rock Paper Scissors/RPS.html new file mode 100644 index 0000000..a6504ff --- /dev/null +++ b/Javascript/Rock Paper Scissors/RPS.html @@ -0,0 +1,17 @@ + + + + + + +

Make your selection

+
+ Rock
+ Paper
+ Scissors
+
+
+ +
+ + \ No newline at end of file diff --git a/Javascript/Rock Paper Scissors/RPS.js b/Javascript/Rock Paper Scissors/RPS.js new file mode 100644 index 0000000..e458b91 --- /dev/null +++ b/Javascript/Rock Paper Scissors/RPS.js @@ -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 + } +} \ No newline at end of file