"YES" instead of "yes"


As the var userAnswer for 'if' statement is case sensitive. So, what if the user answer typing YES instead of yes in the case I assigned the userAnser==="yes"?


If I've understood your problem correctly, your concern is around the fact the user might enter "YES" rather than "yes" therefore causing your if statement to fail.

If that is the case there are a few different things you could do, but by far the easiest would be to force the user answer to a particular case, this will involve taking the answer the user gives and transforming it into upper or lower case:

var a = "yes"
var b = "YES"
a === b // this will return false

But you could correct this, but using .toLowerCase(), so the code would look like:
var a = "yes"
var b = "YES"
a === b.toLowerCase() // this will return true

You can also use .toUpperCase() if you want to convert "yes" to "YES".


Thank you !
What I understand is that weather the user inputs "YES" or "yes" it will return true if I write the writing the code below. Am I right ?

var a = "yes"
var b = "YES"
a === b.toLowerCase() // this will return true


Just to be clear, the use of var a and var b were simply examples to show you how to modify what the user enters before trying to make further checks within your code.

What you are doing when you use .toLowerCase() or .toUpperCase() is changing what the user enters into something that your code is expecting and able to interpret to continue its execution.

So, if your code is only going to work with "yes" rather than "YES", the use of .toLowerCase() would look something like this:

var userChoice = prompt("What is your choice?");

if (userChoice.toLowerCase() === "yes") {
             //Do Something

Hope that helps make things clearer.