<!doctype html> <html> <head> <title> NEW </title> <meta charset='utf-8' /> </head> <body> <canvas id='canvas' width="800" height="600" style="border:1px solid #000000;">Обновите браузер</canvas> <style>#canvas { background-color: rgba(158, 167, 184, 0.2); }</style> <script type = "text/javascript"> var canvas = document.getElementById("canvas"), var ctx = canvas.getContext('2d'); var side = 0; var up = 0; function drawRect () { ctx.fillStyle = "green"; //ctx.clearRect(0, 0, 800, 600); ctx.fillRect (up, side, 25, 25); } //var gameLoop = function () { drawRect (); // side += 5 //}; //gameLoop(); </script> </body> </html> 

Closed due to the fact that off-topic participants Alexey Shimansky , Denis , HamSter , aleksandr barakin , fori1ton Nov 16, '16 at 2:51 pm .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Alexey Shimansky, Denis, HamSter, aleksandr barakin, fori1ton
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • remove var before ctx , or change , to ; after document.getElementById("canvas") - Igor
  • @ Igor thanks helped - Method

1 answer 1

The problem was in var before ctx

 var canvas = document.getElementById("canvas"), ctx = canvas.getContext('2d'), side = 0, up = 0; function drawRect() { ctx.fillStyle = "green"; //ctx.clearRect(0, 0, 800, 600); ctx.fillRect (up, side, 25, 25); } drawRect() 

jsfiddle