javascript - Require user to choose 'boy' or 'girl' -
javascript - Require user to choose 'boy' or 'girl' -
i trying user respond question "are boy or girl?" 1 of 2 choices , forcefulness them take 1 or other.
i think heading in right direction whenever run code, hiccups if choosing sec option.
what doing wrong?
var gender = prompt("are boy or girl?").tolowercase(); while (gender !== ("boy" || "girl")) { gender = prompt("please respond boy or girl. now, boy or girl?"); }
the proper status be
while (gender !== 'boy' && gender !== 'girl'){
that's because ("boy" || "girl")
end "boy", hence while
while(gender !== 'boy')
. ||
in case called "default" operator, clever utilize of logical or . if value on left side truthy, utilize left side value. otherwise, evaluate (hence "default") right side.
javascript prompt
Comments
Post a Comment