9.01 - How to handle invalid input?


9.01 What if a user makes an inappropriate choice like 'dog'?

How can I extend the function to handle that?
I've tried a couple things but I don't know how to get the code to 'reset' if you will, and how to get 'userChoice' to take an input again until a valid input is given...
Thanks for any help :slight_smile:

var userChoice = prompt("Do you choose rock, paper or scissors?");

function checker(userChoice) {
    if (userChoice === "rock") {return true}
    else if (userChoice === "paper") {return true}
    else if (userChoice === "scissors") {return true}
    else {return false}
if (checker = "false") {
    console.log("false return")
    prompt("That wasnt rock, paper or scissors! Try again")


This conversation might help you out:


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