I was wondering if anyone might take a quick look at this program I'm working on for a beginner class...it's brief. I keep getting syntax errors and cannot figure out why. All Firebug tells me is that I have a 'syntax error' for one of the 'else' statements.

An easy way to keep track of the brackets is to label them like this: { //1a........} //1bYou can then see when one or more are missing. I have labelled your script in this way to show you how it works. Once you have established your logic you can remove them. Other things that you need to watch are: There was no <head></head> in your html doc. Also, you put a semi-colon after your if statements like this:if ((red="X")&&(blue="X")&&(green="X")); { This is probably the source of yourr syntax errors. See your script below for the details:

<html>

<head>

</head>

<body>

<script type="text/javascript"><!--// initalizing the values of three variablesvar red = "X", blue = "O", green = "X";//// Per the statements below, check first for three X's// If the criteria isn't met, move onto three O's// If neither condition is met, display "Cat's game"

Thanks for all your help everyone- I really appreciate you taking the time to help out a noob. Think I'll start over from scratch and see if I can make it work with your suggestions & corrections.

Have a great weekend!

Paul_Wilkins
—
2010-10-02T00:19:08Z —
#7

Marple said:

Thank you, that was so quick!

But I do count three sets for a total of 6, 3 opening and 3 closing... does anyone else see a rogue bracket?

Let's simplify, so that we can see the structure more clearly.

if (condition); {
} else {
if (condition);
} else {
}

Those semicolons should not be there, as the if statement then ends at that point.

You may instead be wanting this structure instead:

if (condition) {
} else if (condition) {
} else {
}

felgall
—
2010-10-02T00:17:04Z —
#8

Marple said:

Thank you, that was so quick!

But I do count three sets for a total of 6, 3 opening and 3 closing... does anyone else see a rogue bracket?

Oops - the } on the front of the second else also doesn't belong there since with that there the else has no if to match to (I didn't look past the unnecessary { to see the unnecessary }). So the original code has a } misplaced rather than missing.

The simplest way to tell when this occurs is to always indent your code when you use a { so as to make it clear where the matching } is. The other alternative is to feed it through my formatter at http://javascript.about.com/library/blformat.htm which will indent for you and thus make it obvious which { are being matched to what }

felgall
—
2010-10-01T23:34:37Z —
#9

With the first of the lines that says:

} else {

remove the { or add an extra } to the end of the script to match with it.

If you count the number of { and the number of } you'll see that they don't match.