module.exports = Ball;

function Ball(options, canvas){
  this.r = options.r > 0 && options.r < 20 && options.r || 8; // can be fixed all the time?
  this.x = options.x > 0 && options.x < canvas.width && options.x || 0 + this.r;
  this.y = options.y > 0 && options.y < canvas.height && options.y || 0 + this.r;
  this.sAngle = 0
  this.eAngle = 2 * Math.PI
  this.keyboarder = new Keyboarder
}


Ball.prototype.draw = function(ctx) {
  ctx.beginPath();
  ctx.arc(this.x, this.y, this.r, this.sAngle, this.eAngle);
  ctx.stroke();
  ctx.fillStyle = "blue";
  ctx.fill();
  return this;
};

Ball.prototype.update = function(fallSpeed, keyboarder, ballspeed, canvas){
  this.y += fallSpeed;
  var leftPixel = this.x - 1
  var rightPixel = this.x + 1
  if (this.keyboarder.isDown(this.keyboarder.KEYS.LEFT) && leftPixel > 8) {
    this.x -= ballspeed
  } else if (this.keyboarder.isDown(this.keyboarder.KEYS.RIGHT) && rightPixel < (canvas.width - this.r)) {
    this.x += ballspeed
  } else if (this.y === canvas.height) {
    console.log(this.y)
    this.y = canvas.height
  }
}


Ball.prototype.moveRight = function() {
  this.x++;
  return this;
}

Ball.prototype.moveLeft = function() {
  this.x--;
  return this;
}


var Keyboarder = function() {
  var keyState = {};

  document.onkeydown = function(e) {
    keyState[e.keyCode] = true;
  }

  document.onkeyup = function(e) {
    keyState[e.keyCode] = false;
  }

  this.isDown = function(keyCode) {
    return keyState[keyCode] === true;
  };

  this.KEYS = { LEFT: 37, RIGHT: 39 };
}

@@ -654,24 +654,187 @@
 d, canvas)%7B%0A
+  var topOfCanvas = 0 + this.r%0A  if (this.y === topOfCanvas) %7B%0A    console.log(%22You lose%22)%0A    this.y = this.r%0A  %7D else if (this.y %3C (canvas.height - this.r)) %7B%0A  
   this.y += 
@@ -842,17 +842,20 @@
 allSpeed
-;
+%0A  %7D
 %0A  var l
@@ -1182,32 +1182,8 @@
 ) %7B%0A
-    console.log(this.y)%0A
     

Create boundary at bottom and top of canvas