Hello, help with the timer

When moving the mouse cursor is checked, if the cursor coordinate on x is less than 50, then the dx variable decreases until the OutOfRange variable does not equal to "OOR_N" (the setInterval timer is used), but as a result What is my mistake?

canvas.onmousemove = mouseMove; function mouseMove(event){ movecur(); } function movecur(){ var OutOfRange; if(curx<=50){ OutOfRange="OOR_Y"; function ChangeCanv() { timer1 = setInterval(Change(), 400); } function Change() { dx=dx-10; alert(dx); build(); if (OutOfRange=="OOR_N"){ clearInterval(timer1); } } ChangeCanv(); } build(); } 
  • var OutOfRange - A great name for a variable! With the function can not be confused. - Gena Ant

1 answer 1

Do you distinguish a function call from its one?

 setInterval(Change(), 400); 

that you called the function and passed undefined in setInterval

and it was necessary:

 setInterval(Change, 400);