Uncaught ReferenceError: FPS is not defined how i can correct this error
Hi, I am new to the javascript and got the error Uncaught ReferenceError: FPS is not defined in my code how i can correct this .This is my code:
window.onload = function()
{
//alert("inside function");
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var FPS = 50;
//alert("FPS");
var width = 450;
var height = 450;
Ball();
}
function Ball()
{
//alert("inside function");
this.x = 20;
this.y = 20;
this.radius = 10;
this.speedX = 2;
this.speedY = 2;
this.color = '#000000';
this.draw = function()
{
//alert("inside function");
context.beginPath();
context.arc(this.x, this.y, this.radius, 0, Math.PI*2, true);
context.closePath();
context.fillStyle = this.color;
context.fill();
};
}
var ball = new Ball();
setInterval(function(){
if(ball.x + ball.radius >= width || ball.x - ball.radius <= 0)
{
ball.speedX *= -1;
}
if(ball.y + ball.radius >= height || ball.y - ball.radius <= 0 )
{
ball.speedY *= -1;
}
ball.x = ball.x + ball.speedX;
ball.y = ball.y + ball.speedY;
// clear stage
context.clearRect(0, 0, width, height);
ball.draw();
},
1000/FPS);
</script>
|