+ 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

15th May 2022, 11:51 PM
Mikeey
Mikeey - avatar
5 Respostas
+ 3
Just convert the input to lowercase then compare the result to "yes".
16th May 2022, 12:04 AM
Simon Sauter
Simon Sauter - avatar
15th May 2022, 11:54 PM
Simon Sauter
Simon Sauter - avatar
+ 1
Thanks
16th May 2022, 12:04 AM
Mikeey
Mikeey - avatar
+ 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'...😁
16th May 2022, 5:00 AM
Bob_Li
Bob_Li - avatar
0
I know how to use toLowerCase() I mean I want to make the statement case insensitive
16th May 2022, 12:02 AM
Mikeey
Mikeey - avatar