Why is it that if I remove var framesPerSecond, the program runs fine? Even if I put the variable inside window.onload it doesn't work.
<canvas id="gameCanvas" width="800" height="600"></canvas>
<script>
var canvas;
var canvasContext;
var ballX = 50;
var ballSpeedX = 5;
var framesPerSecond = math.random()*(100-10)+10;
window.onload = function() {
canvas = document.getElementById('gameCanvas');
canvasContext = canvas.getContext('2d');
setInterval(callBoth, framesPerSecond);
}
function callBoth() {
  moveEverything();
  drawEverything();
}
function moveEverything() {
  ballX = ballX + ballSpeedX;
  if(ballX > canvas.width) {
    ballSpeedX = -ballSpeedX;
  }
  if(ballX < 0) {
    ballSpeedX = -ballSpeedX;
  }
}
function drawEverything() {
// canvas
  colorRect(0,0,canvas.width,canvas.height,'black');
// obstacles
  colorRect(40,40,720,520,'blue');
// car
  colorRect(ballX,100,10,10,'white');
}
function colorRect(leftX, topY, width, height, drawColor) {
  canvasContext.fillStyle = drawColor;
  canvasContext.fillRect(leftX, topY, width, height);
}
</script>
Ps. I am just a beginner.
 
    