Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
}
}