Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Java Script Problem Please Help.

I'm learning how to make an HTML5 game but the "index. html" file won't read the JavaScript file. I've checked for errors very thoroughly and am using chrome. I'm trying to make a black rectangle in the canvas.

var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");

imgFrog = new Image();
imgFrog.src = "images/mikethefrog.png";
imgFrog.addEventListener("load",init, false);

var requestAnimFrame =
                window.requestAnimationFrame ||
                window.webkitRequestAnimationFrame ||
                window.mozRequestAnimationFrame ||
                window.oRequestAnimationFrame ||
                window.msRequestAnimationFrame ||
                function (callback) {
                    window.setTimeout(callback, 1000/60);
                };

function init() {
    requestAnimFrame(update);
}

function update() {

    context.fillRect(  10, 10, 40, 380, "#000000");  


    requestAnimFrame(update);
}
<!DOCTYPE html>
<html>
<head>
    <title>My Game</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <canvas id="canvas" width="400" height="400"></canvas>
    <script src="game.js"></script>
</body>
</html>
body {
    background: #999999;
}
canvas {
    display: block;
    background: #FFFFFF;
     margin: 0 auto;
}
Greg Kaleka
Greg Kaleka
39,021 Points

Hey Isaac,

Can you wrap your code in markdown tags like this:

```JavaScript

[All of your code]

```

This will format and color your code to make it more readable.

Sure.

How do I edit my post?

Greg Kaleka
Greg Kaleka
39,021 Points

Next to Add Comment there's a small ... icon. If you click it, "Edit Post" is an option.

Thanks

3 Answers

Can you post the code for your index.html file?

Okay i'll try.

just post it like:

```HTML

[your code here]

Want me to post the Css file too?

Greg Kaleka
Greg Kaleka
39,021 Points

Probably just need the HTML.

Okay, I posted them all.