2

I set the function called "drawEverything()" to run onload, however the function doesn't run and I get a bug in Firebug saying "drawEverything is not defined"?? Thing is, I did define it!

I googled the problem and most of the time it was due to some kind of syntax error, but I've looked all over it and can't find any syntax errors.

My code is as follows:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<link rel=stylesheet href="style.css" type="text/css">
</head>

<script type="text/javascript">

var new_x = 110;
var new_y = 150;
function drawEverything(){
    var temp_x = new_x;
    var temp_y = new_y;

    var c = document.getElementById("myCanvas");
    var ctx = c.getContext("2d");
    for (int i = 0; i < 5; i++){
        ctx.beginPath();
        ctx.arc(temp_x,temp_y,20,0,2*Math.PI);

        ctx.stroke();
        if ((i < 3) || (i == 4)){
            temp_x += 40;
        }
        else if (i == 3){
            temp_y += 20;
            temp_x -= 60;
        }
    }
}
</script>

<body onload = "drawEverything()">
<h1>Interactive Olympic Rings</h1>
<div id="container">
<canvas id="myCanvas" width="300" height="300"></canvas>
</div>

</body>
</html>

Any help would be appreciated, thanks!

1
  • 4
    You have your script in the twilight zone, between the head and the body, where nothing can exist! Commented Dec 9, 2012 at 11:53

2 Answers 2

4

Deal with your errors in order. Later errors can be a consequence of earlier one.

First error (as reported by firebug):

SyntaxError: missing ; after for-loop initializer
[Break On This Error]   

for (int i = 0; i < 5; i++){

Second error:

ReferenceError: drawEverything is not defined

Since the function definition has compile time errors in it, it is not defined when you come to run it.

You want var not int.

Sign up to request clarification or add additional context in comments.

Comments

0

You cannot use int here. Use var in javascript

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.