/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Javascript syntax error I just can’t find…

Hi,

Maybe I’m just too tired, but I can’t find the syntax error in this code. Can you see it? When I take it out of my program, the program runs fine.

Thanks…

[code]
function firstcapture_funds(){
if(newcaptureEditsFlag!=”EDITS” && (window_firstcapture==”” || window_firstcapture.closed)){window_firstcapture=new_window(‘/first_capture.htm’,400,230,’firstcapture’);}
else{window_firstcapture.focus();}
else if(window_secondcapture==”” || window_secondcapture.closed){window_firstcapture=new_window(‘/first_capture.htm’,400,230,’firstcapture’);}
else{window_firstcapture.focus();}
}

[/code]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@chestertbMay 15.2007 — I've found it easier to track bugs when the code's written like this...

[code=html]function firstcapture_funds()
{
if(newcaptureEditsFlag!="EDITS" && (window_firstcapture=="" || window_firstcapture.closed))
{
window_firstcapture=new_window('/first_capture.htm',400,230,'firstcapture');
}
else
{
window_firstcapture.focus();
}
else if(window_secondcapture=="" || window_secondcapture.closed)
{
window_firstcapture=new_window('/first_capture.htm',400,230,'firstcapture');
}
else
{
window_firstcapture.focus();
}
}[/code]


And you should be able to see the error immediately.

You've got an if followed by an else, followed by an else if, followed by another else.

Cheers

CTB
Copy linkTweet thisAlerts:
@DokMay 15.2007 — First of all...use proper indents

[CODE]function firstcapture_funds() {
if (newcaptureEditsFlag!="EDITS" && (window_firstcapture=="" || window_firstcapture.closed)) {
window_firstcapture=new_window('/first_capture.htm',400,230,'firstcapture');
}
else {
window_firstcapture.focus();
}
else if (window_secondcapture=="" || window_secondcapture.closed) {
window_firstcapture=new_window('/first_capture.htm',400,230,'firstcapture');
}
else {
window_firstcapture.focus();
}
}[/CODE]


You can't have an else-block followed by a else-if-block
Copy linkTweet thisAlerts:
@mrhooMay 15.2007 — 1.the bracket after first else in your code closes the function

2.after a simple else statement, there is no logic to the following else if- the else has run for all alternatives to the first if...
Copy linkTweet thisAlerts:
@Mike_BurdickauthorMay 15.2007 — Thanks Guys!

Got it!?
×

Success!

Help @Mike_Burdick 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.15,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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