How do I accept multiple answers as true in Choose Your Own Adventure?


#1

For example, I want my if/else to accept both "Yes" and "yes" as true. Ideally, it'd take others as well- but I don't know how to accept more than once answer. In this example, the code says "yes" is true, but I tend to capitalize in online forms and when I did it there it still gave me the else option, even though the only difference was capitalization.

Thanks for the help!


#2

The easiest thing would be to do:

var userinput=prompt("enter yes or no").toUpperCase();

this will transform the text to upper (you can also use lower) case. This would be the easiest solution, if you just want to accept yes and Yes you could use or:

if (userinput == 'yes' || userinput == 'Yes'){}

|| is an or statement, one of these condition have to be true, in order for the if statement to be executed. I i would use to upper to lower method to cover every case


#3

Perfect. Thank you so much for your help!