/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] If , else if loop

So, im defining my variable, then trying to get this to write the content in the array that is specified if it returns one of the referrers true.. For some reason it only displays mycontent[0] even though i’ve defined to print mycontent[1].. can anybody tell me where i went wrong?

[CODE]
<script type=”text/javascript”>
var referrer= “www.google.com”;

var mycontent = new Array();
mycontent[0]=’no from yahoo because..’
mycontent[1]=’no from google because..’
mycontent[2]=’no from msn because..’

if (referrer = “www.yahoo.com”) {
document.write(mycontent[0]);
}else if (referrer = “www.google.com”)
{document.write(mycontent[1]);
}else if (referrer = “www.msn.com”)
{document.write(mycontent[2]);
}else {
document.write(‘NO MATCH’);
}
</script>
[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@ShortsJun 17.2009 — use == instead of = inside of the ifelse statements

= means that you are setting referrer equal to the string, which will return true, making that statement true and changing referrer = www.yahoo.com

so referrer == 'www.yahoo.com' and so on is what you're looking for ?
Copy linkTweet thisAlerts:
@absolutmgd13authorJun 17.2009 — your my hero.. thanks a lot! haha
×

Success!

Help @absolutmgd13 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 6.1,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

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