Compare commits
2 Commits
97544cafe5
...
bd24adc2d7
Author | SHA1 | Date | |
---|---|---|---|
|
bd24adc2d7 | ||
|
65b89e8ac0 |
72
script.js
72
script.js
@ -42,35 +42,77 @@ function getComputerChoice(){
|
|||||||
|
|
||||||
function playRound(playerSelection, computerSelection){
|
function playRound(playerSelection, computerSelection){
|
||||||
let result = "It's a Tie!";
|
let result = "It's a Tie!";
|
||||||
|
playerSelection = playerSelection.toLowerCase();
|
||||||
|
|
||||||
if (playerSelection === "rock" && computerSelection == "paper"){
|
if (playerSelection === "rock" && computerSelection == "paper"){
|
||||||
console.log(playerSelection, computerSelection);
|
result = "You Lose! Paper beats Rock";
|
||||||
return result = "You Lose! Paper beats Rock";
|
console.log(playerSelection, computerSelection, result);
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else if(playerSelection === "paper" && computerSelection == "rock"){
|
else if(playerSelection === "paper" && computerSelection == "rock"){
|
||||||
console.log(playerSelection, computerSelection);
|
result = "You Win! Paper beats Rock";
|
||||||
return result = "You Win! Paper beats Rock";
|
console.log(playerSelection, computerSelection, result);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else if(playerSelection === "paper" && computerSelection == "scissors"){
|
else if(playerSelection === "paper" && computerSelection == "scissors"){
|
||||||
console.log(playerSelection, computerSelection);
|
result = "You Lose! Scissors beats Paper";
|
||||||
return result = "You Lose! Scissors beats Paper";
|
console.log(playerSelection, computerSelection, result);
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else if(playerSelection === "scissors" && computerSelection == "paper"){
|
else if(playerSelection === "scissors" && computerSelection == "paper"){
|
||||||
console.log(playerSelection, computerSelection);
|
result = "You Win! Scissors beats Paper";
|
||||||
return result = "You Win! Scissors beats Paper";
|
console.log(playerSelection, computerSelection, result);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else if(playerSelection === "rock" && computerSelection == "scissors"){
|
else if(playerSelection === "rock" && computerSelection == "scissors"){
|
||||||
console.log(playerSelection, computerSelection);
|
result = "You Win! Rock beats Scissors";
|
||||||
return result = "You Win! Rock beats Scissors";
|
console.log(playerSelection, computerSelection, result);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else if(playerSelection === "scissors" && computerSelection == "rock"){
|
else if(playerSelection === "scissors" && computerSelection == "rock"){
|
||||||
console.log(playerSelection, computerSelection);
|
result = "You Lose! Rock beats Scissors";
|
||||||
return result = "You Lose! Rock beats Scissors";
|
console.log(playerSelection, computerSelection, result);
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
console.log(playerSelection, computerSelection);
|
console.log(playerSelection, computerSelection,result);
|
||||||
return result;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
console.log(playRound("Paper", getComputerChoice()));
|
// console.log(playRound("Paper", getComputerChoice()));
|
||||||
|
|
||||||
|
function game(){
|
||||||
|
let player = 0;
|
||||||
|
let computer = 0;
|
||||||
|
let win = "You win";
|
||||||
|
|
||||||
|
while (player || computer < 5) {
|
||||||
|
let party = playRound(prompt("Rock, Paper or Scissors?"), getComputerChoice());
|
||||||
|
|
||||||
|
if(party === true){
|
||||||
|
player +=1;
|
||||||
|
}
|
||||||
|
else if(party === false){
|
||||||
|
computer +=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Player score: ${player}/5, Computer score: ${computer}/5`);
|
||||||
|
|
||||||
|
if(player === 5){
|
||||||
|
return win = "You win!";
|
||||||
|
}
|
||||||
|
else if(computer === 5){
|
||||||
|
return win = "Computer wins!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(game());
|
Loading…
Reference in New Issue
Block a user