javascript - Require user to choose 'boy' or 'girl' -


I am trying to answer the question to my user "Are you a boy or a girl?" With one of those two options and forcing them to choose one or the other.

I think I am going in the right direction, but whenever I run my code, when I choose the second option, this hitchie

What am I doing?

  var gender = sign ("Are you a boy or a girl?"). ToLowerCase (); While (gender! == ("boy" || "girl")) {gender = sign ("please only respond to the boy or girl now, are you a boy or a girl?"); }    

appropriate status

  will be (gender! == 'boy' & gender! == 'girl') {  

That's because ("boy" || "girl") always " Boy ", so the looks like while while (gender! == 'boy') . In this case || is called "default" operator, logical or a stunning use. If the value on the left is true, then it will use the value to the left. Otherwise, it will evaluate (hence "default") on the right side.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

c++ - Qt::make_shared for creating QSharedPtr as std::make_shared for creating std::shared_ptr -