Write game function and successfully test it
This commit is contained in:
parent
c267800ab9
commit
caed7d3804
1 changed files with 33 additions and 7 deletions
40
script.js
40
script.js
|
|
@ -39,8 +39,38 @@ function playRound(playerSelection, computerSelection){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function game(playerSelection, computerSelection) {
|
function game() {
|
||||||
for (var i = 0; i < 5; i++) {}
|
let p = 0;
|
||||||
|
let c = 0;
|
||||||
|
|
||||||
|
for (var i = 0; i < 5; i++) {
|
||||||
|
const ps = prompt("Rock, Paper or Scissors?");
|
||||||
|
const cs = getComputerChoice();
|
||||||
|
|
||||||
|
play = playRound(ps, cs);
|
||||||
|
|
||||||
|
switch (play) {
|
||||||
|
case "player loses":
|
||||||
|
c += 1;
|
||||||
|
console.log("You lost!");
|
||||||
|
break;
|
||||||
|
case "player wins":
|
||||||
|
p += 1;
|
||||||
|
console.log("You won!");
|
||||||
|
break;
|
||||||
|
case "tie":
|
||||||
|
p += 1;
|
||||||
|
c += 1;
|
||||||
|
console.log("It's a tie!");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.log("Invalid selection. Please choose Rock, Paper or Scissors to play.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Computer won " + c + " games");
|
||||||
|
console.log("Player won " + p + " games");
|
||||||
|
|
||||||
//playRound(playerSelection, computerSelection)
|
//playRound(playerSelection, computerSelection)
|
||||||
|
|
||||||
//count how many times p and c have won
|
//count how many times p and c have won
|
||||||
|
|
@ -49,8 +79,4 @@ function game(playerSelection, computerSelection) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ps = prompt("Rock, Paper or Scissors?"); //need to make sure only one of those three options are chosen
|
console.log(game());
|
||||||
const cs = getComputerChoice();
|
|
||||||
|
|
||||||
//console.log(game(ps, cs))
|
|
||||||
console.log(playRound(ps, cs));
|
|
||||||
Loading…
Reference in a new issue