Skip to content

Commit

Permalink
Finish all the necessary features for game
Browse files Browse the repository at this point in the history
  • Loading branch information
apfossdev committed Mar 7, 2024
0 parents commit dca60cc
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rock Paper Scissors</title>
</head>
<body>


<script src="script.js"></script>
</body>
</html>
74 changes: 74 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
let options = ["ROCK", "PAPER", "SCISSORS"];
let playerScore = 0;
let computerScore = 0;


function getComputerChoice(){
let randomNum = Math.floor(Math.random() * 3);
return options[randomNum];
}

function playRound(playerSelection, computerSelection) {

playerSelection = playerSelection.toUpperCase();

if ((playerSelection == "ROCK" && computerSelection == "ROCK") || (playerSelection == "PAPER" && computerSelection == "PAPER") || (playerSelection == "SCISSORS" && computerSelection == "SCISSORS")){
return "You Draw!";
}

else if (playerSelection == "ROCK" && computerSelection == "SCISSORS"){
playerScore++;
return "You Win! Rock beats Scissors";
}

else if (playerSelection == "ROCK" && computerSelection == "PAPER") {
computerScore++;
return "You Lose! Paper beats Rock"
}

else if (playerSelection == "PAPER" && computerSelection == "SCISSORS"){
computerScore++;
return "You Lose! Scissors beats Paper";
}

else if (playerSelection == "PAPER" && computerSelection == "ROCK") {
playerScore++;
return "You Win! Paper beats Rock"
}

else if (playerSelection == "SCISSORS" && computerSelection == "ROCK"){
computerScore++;
return "You Lose! Rock beats Scissors";
}

else if (playerSelection == "SCISSORS" && computerSelection == "PAPER") {
playerScore++;
return "You Win! Scissors beats Paper";
}

}


function playGame() {

for(let i=0; i<5; i++){
let playerSelection = prompt("Choose Rock, Paper or Scissors...");
let computerSelection = getComputerChoice();
console.log(playRound(playerSelection, computerSelection));
console.log(playerSelection);
console.log(computerSelection);
console.log("Player Score:"+ playerScore);
console.log("Computer Score:"+ computerScore);
}
if (playerScore > computerScore){
console.log("You Win :)");
}
else if(playerScore == computerScore){
console.log("It's a Draw:|");
}
else {
console.log("You Lose :(");
}
}

playGame();

0 comments on commit dca60cc

Please sign in to comment.