+ 1
How to make a js statement string insensitive
Hey guys... Pls I want to make my JavaScript code if statement insensitive using the comparison operator Here's the statement If ( input == "yes") { document.write("hi"); } else { document.write("hello"); } I want to make the if statement input to be insensitive so any style of the input whether uppercase or lower will still run
5 Respostas
+ 3
Just convert the input to lowercase then compare the result to "yes".
+ 1
Thanks
+ 1
Michael
Simon Sauter said it. You can't control what case the user inputs 'yes'... it could be 'YES', 'Yes','yEs'... all kinds of crazy.
What you can do is to convert it to lowercase.
Then your if statement will work.
Unless the user inputs 'ok'...😁
0
I know how to use toLowerCase()
I mean I want to make the statement case insensitive