# Why Won't Image Drawing Work In JavaScript

In my game at the beginning the first thing that you'll see is a campfire with this code:

 var campfire = new Image();
ctx.drawImage(campfire, campfireX, campfireY);
};
campfire.src = "Sprites/Campfire.png";


However, it doesn't work, I put an

alert("All systems a-ok");


at the end and i get the alert so i don't understand why it's there. You can find the actual image file here and the full code here. Sorry if I didn't format this well or something, I'm not very good at this =3

This may seem similar to an older question of mine in which I stated how to add a sprite onto the canvas, though in this case, I'm asking why the image doesn't appear on the canvas at all, even though there's no errors.

• The reason you see your alert even if the image didn't load is because onload is a callback function. Put your alert inside that function. Use the dev tools in your browser to debug this. In this case prefer console.log('loaded'); over alert to avoid having to click the alert. – Neil Jan 7 '17 at 11:57

You should use this (literally):

var campfire = new Image();