Write playRound function and successfully test it

This commit is contained in:
lolabird 2023-09-30 10:47:14 -06:00
commit 1f986c09e7

View file

@ -11,14 +11,33 @@ function getComputerChoice(){
} }
function playRound(playerSelection, computerSelection){ function playRound(playerSelection, computerSelection){
//p = playerSelection.toLowerCase() p = playerSelection.toLowerCase();
//c = computerSelection.toLowerCase() c = computerSelection.toLowerCase();
// if player && comp === "rock", || if p && c === "paper" || p && c === "scissors" return "tie" if (p === c) {
return "tie";
//else if p === "rock" } else if (p === "rock") {
//if c === "paper" player loses if (c === "paper") {
//else if c === "scissors" player wins return "player loses";
} else { //scissors
return "player wins"
}
} else if (p === "paper") {
if (c === "scissors") {
return "player loses";
} else { //rock
return "player wins"
}
} else if (p === "scissors") {
if (c === "paper") {
return "player loses";
} else { //scissors
return "player wins"
}
} else {
return "not a valid entry"
}
//else if p === "paper" //else if p === "paper"
//if c === "scissors" player loses //if c === "scissors" player loses
//if c === "rock" player wins //if c === "rock" player wins
@ -43,4 +62,4 @@ const ps = prompt("Rock, Paper or Scissors?"); //need to make sure only one of t
const cs = getComputerChoice(); const cs = getComputerChoice();
//console.log(game(ps, cs)) //console.log(game(ps, cs))
console.log(ps +" " + cs) console.log(playRound(ps, cs));