/    Sign up×
Community /Pin to ProfileBookmark

javascript starter help

what’s wrong with this code

[CODE]<html>
<body>
<script>
var age=prompt(“what’s your age”)
var gen=prompt(“what’s your gge”)
if
(age>=21 && gen=male) || (age>=18 && gen=female)
{
document.write(“eligble”)
}
else
{
document.write(“not eligble”)
}
</script>
</body>
</html>
[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Sup3rkirbyJan 15.2013 — With your if statement grouping, you are missing an extra parenthesis for each pairing which breaks that if statement.

Also the comparison of the gen variable needs to use the == comparison operater (just a single = sets a variable, 2 or 3 = signs will compare).

And the male and female comparison strings much be enclosed in some form of a quote.

It also would be proper practice to use semi-colons at the end of each proper line of code:
<i>
</i>&lt;html&gt;
&lt;body&gt;
&lt;script&gt;
var age=prompt("what's your age");
var gen=prompt("what's your gge");
if((age&gt;=21 &amp;&amp; gen=="male") || (age&gt;=18 &amp;&amp; gen=="female")) {
document.write("eligble");
} else {
document.write("not eligble");
}
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@leonightauthorJan 15.2013 — tons of thanks sir problem solved and i have learned something very important?
×

Success!

Help @leonight spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...