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 trialIsaac Oleksiuk
Courses Plus Student 99 PointsJava 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;
}
Isaac Oleksiuk
Courses Plus Student 99 PointsSure.
Isaac Oleksiuk
Courses Plus Student 99 PointsHow do I edit my post?
Greg Kaleka
39,021 PointsNext to Add Comment there's a small ... icon. If you click it, "Edit Post" is an option.
Isaac Oleksiuk
Courses Plus Student 99 PointsThanks
3 Answers
David Tonge
Courses Plus Student 45,640 PointsCan you post the code for your index.html file?
Isaac Oleksiuk
Courses Plus Student 99 PointsOkay i'll try.
David Tonge
Courses Plus Student 45,640 Pointsjust post it like:
```HTML
[your code here]
Isaac Oleksiuk
Courses Plus Student 99 PointsWant me to post the Css file too?
Greg Kaleka
39,021 PointsProbably just need the HTML.
Isaac Oleksiuk
Courses Plus Student 99 PointsOkay, I posted them all.
Greg Kaleka
39,021 PointsGreg Kaleka
39,021 PointsHey 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.