Question for my rock paper scissors game

For my coding class im supposed to make a rock paper scissors game that goes until the computer or player gets 3 wins. It has 3 functions and the last one is the one that repeats it but im not sure how to do the functions again. Can someone please tell me how to do this
https://codepen.io/coderkoji/pen/dyNrjjq

Please can someone just look at it

Hi r u needing help.

Yeah, I agree with Randy. Adding on to that…

let choice = prompt("Rock, Paper, or Scissors")
 
const yourTurn = () => {
  let choose = ""
  if(choice == "cancel"){
    let choose = "nothing"
    return(choose)
  }
  if(choice == "Rock" || "Paper" || "Scissors"){
    choice = choice.toLowerCase();
    return(choice)
  }
}

Is that where the prompt should be? I would expect it to be inside the function so it gets run each time.


This here:

  if(player == "rock"){
    if(bot == "paper"){
     alert("You chose " + player +  " and computer chose " + bot + ". Therefore you lose this round")
       computerScore += 1;
    }
    if(bot == "scissors"){
     alert("You chose " + player +  " and computer chose " + bot + ".  Therefore you win this round")
       playerScore += 1;
    }
  }
  if(player == "paper"){
    if(bot == "scissors"){
      alert("You chose " + player +  " and computer chose " + bot + ". Therefore you lose this round")
      computerScore += 1;
    }
    if(bot == "rock"){
      alert("You chose " + player +  " and computer chose " + bot + ".  Therefore you win this round")
      playerScore += 1;
    }
  }
  if(player == "scissors"){
    if(bot == "rock"){
      alert("You chose " + player +  " and computer chose " + bot + ". Therefore you lose this round")
      computerScore += 1;
    }
    if(bot == "paper"){
      alert("You chose " + player +  " and computer chose " + bot + ".  Therefore you win this round")
      playerScore += 1;
    }
  }

Those are all doing the exact same thing. I feel like these could be simplified a great deal. Really this should all just be an else of the previous if and this could probably all be completed with an if/else of its own. But maybe you want to leave this as is if you don’t want to get bogged down optimizing this - it just caught my eye.


while(playerScore <= 2 || computerScore <= 2){

Is that the right logic?


Your instructions say:

  1. Write a function, findResult(), which takes in the player choice and computer choice and returns “win”, “lose”, or “tie” based on the user’s results.

That’s not what it’s doing right now.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.