-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish all the necessary features for game
- Loading branch information
0 parents
commit dca60cc
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |