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

Have you learned about while or for loops? You could use either to repeat the call of a function. You would just need to track both the player and computer wins in some way and have the game alert and call printToScreen showing who won after either player gets 3 wins.

Hint: Using a while loop might be the easiest as you can have the while loop’s condition check if at least if both of the players do not have 3 wins. Once that condition is no longer met, the loop will complete and you can figure out which has one and display results accordingly.

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.