[Javascript] Problem with my first code via /r/learnprogramming


[Javascript] Problem with my first code

So I've been watching a free course in basic programming to get started. It shows basic stuff and is supposed to teach me how to make a basic tennis game Like this

Im stuck on a step the instructor had no problem with. I've tried copying the code he has as good as I can but it still doesn't work.

Here is the code for context

 function drawEverything() { // next line blanks out the screen with black colorRect(0,0,canvas.width,canvas.height,"black"); // this is left player paddle colorRect(0,210,10,100,"white"); //this is the ball colorRect(ballX,100,10,10,"red"); } > function colorRect(leftX,topY, width,height, drawColor) { canvasContext.fillStyle = "drawColor"; canvasContext.fillRect(leftX,topY, width,height); } 

This section is where it messed up. I think the bottom part is supposed to decide what color the different elements are.

This was the code before "cleaning it up" as the instructor said.

function drawEverything() { canvasContext.fillStyle = "black"; canvasContext.fillRect(0,0,canvas.width,canvas.height); canvasContext.fillStyle = "white"; canvasContext.fillRect(0,210,10,100); canvasContext.fillStyle = "red"; canvasContext.fillRect(ballX,100,10,10); } 

This version worked for me, but when I changed it the to one at the top, it worked for him and not me.

Where have I messed up?

Submitted July 09, 2017 at 11:51AM by Axekan
via reddit http://ift.tt/2tWDiQd

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s