Hi there.
This is not the usual thing to ask here (I’d go for some sort of Javascript
forum in the future).
I think you don’t need to include any sort of HTML here to get ppl to look at
your JS.
First problem:
You have a ; after the end of your if block (I’ve marked it below), that ends
the if else statement too early. Else cannot stand alone so to speak.
Second problem: your blocks are not entirely right here. The parser can only
follow the rules here. The if sentence either deals with the next statement
(line) or block. Only if that line or block is directly followed by an else or
else if can that be included. A corrected (untested assumption here) example
could be (there is more than one way to do it):
var a = “0”
var b = “c”
if (a == “0”)
{
if (b == “b”)
{
alert(“a is o”);
alert(“b is b”);
}
}
else
{
alert(“a is not o”);
}
/Mikael
When I try this code -
<!DOCTYPE HTML>
<html>
<script>
var a = "o";
var b = "c";
if (a == "o")
if (b == "b")
{
alert("a is o");
alert("b is b");
}; ß Problem here
else
{
alert("a is not o");
};
</script>
</html>
It shows -
Uncaught SyntaxError: Unexpected token else
Should that error be triggered? can you explain why?
Also, running it without that semicolon -
<!DOCTYPE HTML>
<html>
<script>
var a = "o";
var b = "c";
if (a == "o")
if (b == "b")
{
alert("a is o");
alert("b is b");
}
else
{
alert("a is not o");
};
</script>
</html>
Shows an alert - "a is not o".
As far as I know, "if" and "else" count as two statements. If they are, the
"else" block is actually part of the first "if" statement.
Am I misinformed, or is it a bug?
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users