How do I fix this Javascript ?

I’d like to see my application to showcase “girl” if the user inputs “F” along with “boy” should they enter anything else.
and this i have previously – (p.utes.could you also tell me what used to do wrong! thanx!!! )

Make a Story

if (heroGender = (“F”)) should be if (heroGender == (“F”))

Equal signals have special rules practically in programming languages.A sole equal warning (=) assigns your value.A dual (==) can be used for assessment.A double (===) implies you’re making a comparison involving both benefit and variable type.

Precisely what you’re basically doing you can find assigning the worthiness “F” for you to heroGender as part of your if statement, rather as compared to checking to check out if that’s on-line it witout a doubt holds.

== could normally perform however, it doesn’t always perform.Sometimes you have the dilemma whenre == comes anywhere close the memory space addresses where the values are and never the real values.The most effective:-

Either:-
if((heroGender == “F”) (heroGender == “f”)) // accommodate for each upper plus lower instances.

// stuff

Or perhaps:
if((heroGender.equals(“F”)) (heroGender.equals(“f”))) // accommodate for each upper plus lower instances.

// stuff

You may, obviously turn to upper/lower case prior to comparison saving the OR component to the problem.

Leave a Reply