swydell
swydell

Reputation: 2020

if, if else statement producin error message

I understand that each if statement and each if else statement is contained inside curly braces. That's what I've done here so far. I just started this code and I tested it with only 20% done so that I can fix errors before the code get's too long. With everything looking correct I'm getting a syntax error that for the life of me I can't see where it is. Any suggestions? Here is the code. And here is the link: stickFigure

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>The mysterious road</title>
</head>
<script type="text/javascript">
var curScene = 0

function changedScene(decision){
var message = "";

if(curScene==0) {
curScene=1;
message = "Let the games began!";
}
else if(curScene ==1){
if(decision==1){
    curScene = 2;
    message = "Looks like you're on the right road.";
}
else(curScene = 3);
message = "you're stading on a bridge overlooking a peaceful stream.";
}

document.getElementById("sceneimg"). src = "scene" + curScene + .png; //There's a syntax  error       here that I don't see!
alert(message);
}
</script>

<body>
<div style="margin-top:100px; text-align:center">
<p><img id="sceneimg" src="../sfa/scene0.png" alt="Stick Figure" /></p>

Enter here for a glorious adventure!
<input type="button" id="decision" value="1" onclick="curScene(1)" />
Enter this gate for the surpirse of your life!
<input type="button" id="decision" value="2" oonclick="curScene(2)" />
</div>

</body>
</html>

Upvotes: 0

Views: 337

Answers (3)

LowTechGeek
LowTechGeek

Reputation: 441

Also, even though JavaScript allows it, you're missing a semicolon after your first script statement:

var curScene = 0

Be aware of such omissions. Even though it's not a syntax or semantics error here, this could get you into trouble elsewhere, such as (made up):

return  // return undefined
val1 + val2;

Because you use semicolons every where else to terminate your statements, it's best to be consistent.

Upvotes: 0

david
david

Reputation: 4278

for the first syntax error you are aware of add say double quoats around the ".png"

and you havent got got ant objects that support the method (no functions found) calling curScene(1) and your only function is changedScene() plus a typo with the oonclick. and what fearofawhackplanet said.

stick with it, dont give up

Upvotes: 0

fearofawhackplanet
fearofawhackplanet

Reputation: 53396

Look here

else(curScene = 3);

and you should be able to work it out.

Upvotes: 1

Related Questions