I was reading the June 2011 issue of Wired magazine the other day, and I came across an ad for Louisiana Economic Development, presumably written in ActionScript.
I originally thought that it was a clever ad, but after looking into it, it seems like there's a fairly obvious bug in the code.
Is it just me, or should that break
be a return
?
I'd call it a bug, since the desired outcome would most likely be to navigate to the URL if any one of those interests is held and do nothing if none of them are. As such, I would change the logic to the following (ignoring for the moment the issues mentioned in the comment from scriptocalypse):
if (this.innovator.hasInterestIn(interest[i])){
navigateToURL("www.OpportunityLouisiana.com/digital");
return;
}
Of course, this wouldn't look as good in an ad, since the URL wouldn't be prominently displayed at the bottom of the code. Perhaps a better alternative would be to organize the logic in the loop like this:
if (this.innovator.hasInterestIn(interest[i])){
break;
} else if (i == n-1){
return;
}
Wouldn't call it a bug as much as faulty logic...the break will get you out of the loop, but if you enter that function you're navigating to that URL, whether you're interested in all those things or not.
Yep, that should be a return. Right now, as the code stands, navigatetoUrl will fire even if the user has none of the interests.
The code only navigates to that page regardless of variables before the function and if this is the intention of the function then it is correct but badly implemented because the loop and everything before it are redundant. Perhaps the ad is a call for help, being that the code is faulty and that the company is looking to hire able developers to correct the mistakes of those already employed.