Skip to content
Sign upLog in
← Back to Community

I have an error, and I cannot fix it.

Profile icon
Logimite

I am making a program with JavaScript using an HTML canvas. Error: Expected '}'.I tried really hard to see what is the error, but all of the braces look even. Help would be appreciated. This is the link to my code: https://repl.it/@laksh5/The-Blob-Game.

Voters
Profile icon
KabaroKun
Profile icon
girliecodes
Profile icon
mairarojas
Profile icon
Djbrimpipompi
Profile icon
Logimite
Comments
hotnewtop
Profile icon
a5rocks

Have you fixed your error yet? Running your code doesn't give me Error: Expected '}'. Going through a couple errors (extra newline in html, forgot a comma in person setup, misspelled function as functon) gives me an error for .getcontext, which I don't know :/.

tl;dr please update your question so that we can know your current problem.

Also, it seems you are trying to follow this tutorial : https://repl.it/talk/learn/JavaScript-Games-Tutorial-3-the-Canvas/11299. Try taking the exact code from it, then tweaking the stolen absorbed code to get what you want.

Profile icon
Logimite

I fixed my other errors, and now I get this: TypeError: Unable to get property 'getContext' of undefined or null reference
at Global code (https://replbox.repl.it/data/web_hosting_1/laksh5/The-Blob-Game/script.js:3:1). Is this what you got, too?

Profile icon
ArchieMaclean

@laksh5
Try this:
add this to your html (ABOVE the js source):

<canvas id="game-canvas" width="200" height="200"></canvas>

Then line 3 on the js file changes to this:

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

Please upvote if this helps :)

Profile icon
Logimite

@ArchieMaclean
Thank you
@ArchieMaclean
It helped, however, it does not give any output except a black rectangle. Please help if you find a solution.

Profile icon
ArchieMaclean

@laksh5
There isn't any output because there is no code for outputting anything except lines 62/63:

context.fillStyle = "#202020"; context.fillRect(0, 0, 320, 100);

And that is outputting the black rectangle.
What do you want to output?

Profile icon
ArchieMaclean

@a5rocks
There's nothing wrong with following a tutorial.

Profile icon
Logimite

@ArchieMaclean
I want to output a platformer game.