var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
var ballRadius = 10;
var x = canvas.width/2;
var y = canvas.height-30;
var dx = 2;
var dy = -2;
var paddleHeight = 10;
var paddleWidth = 75;
var paddleX = (canvas.width-paddleWidth)/2;
var rightPressed = false;
var leftPressed = false;
var brickRowCount = 3;
var brickColumnCount = 5;
var brickWidth = 75;
var brickHeight = 20;
var brickPadding = 10;
var brickOffsetTop = 30;
var brickOffsetLeft = 30;
var bricks = [];

for(c=0; c<brickColumnCount; c++) {
    bricks[c] = [];
    for(r=0; r<brickRowCount; r++) {
        bricks[c][r] = { x: 0, y: 0, status: 1 };
    }
}
document.addEventListener("keydown", keyDownHandler, false);
document.addEventListener("keyup", keyUpHandler, false);


function drawBall(){
  ctx.beginPath();
  ctx.arc( x, y, ballRadius, 0, Math.PI*2);

  ctx.fill();
  ctx.closePath();
}

function getRandomColor() {
    var letters = '0123456789ABCDEF'.split('');
    var color = '#';
    for (var i = 0; i < 6; i++ ) {
        color += letters[Math.floor(Math.random() * 16)];
    }
    return color;
}

function drawPaddle() {
    ctx.beginPath();
    ctx.rect(paddleX, canvas.height-paddleHeight, paddleWidth, paddleHeight);
    // ctx.fillStyle = "#0095DD";
    ctx.fill();
    ctx.closePath();
}
function keyDownHandler(e) {
    if(e.keyCode == 39) {
        rightPressed = true;
    }
    else if(e.keyCode == 37) {
        leftPressed = true;
    }
}

function keyUpHandler(e) {
    if(e.keyCode == 39) {
        rightPressed = false;
    }
    else if(e.keyCode == 37) {
        leftPressed = false;
    }
}

function drawBricks() {
  for(c=0; c<brickColumnCount; c++) {
    for(r=0; r<brickRowCount; r++) {
      if(bricks[c][r].status == 1) {
        var brickX = (c*(brickWidth+brickPadding))+brickOffsetLeft;
        var brickY = (r*(brickHeight+brickPadding))+brickOffsetTop;
        bricks[c][r].x = brickX;
        bricks[c][r].y = brickY;
        ctx.beginPath();
        ctx.rect(brickX, brickY, brickWidth, brickHeight);
        ctx.fillStyle = "#0095DD";
        ctx.fill();
        ctx.closePath();
      }
    }
  }
}

function collisionDetection() {
  for(c=0; c<brickColumnCount; c++) {
    for(r=0; r<brickRowCount; r++) {
      var b = bricks[c][r];
      if(b.status == 1) {
        if(x > b.x && x < b.x+brickWidth && y > b.y && y < b.y+brickHeight) {
          dy = -dy;
          b.status = 0;
        }
      }
    }
  }
}

function draw() {
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  drawBall();
  drawPaddle();
  drawBricks();
  collisionDetection();

  if(x + dx < ballRadius || x + dx > canvas.width-ballRadius){
    dx = -dx;
    ctx.fillStyle = getRandomColor();
  }
  if(y + dy < ballRadius){
    dy = -dy;
    ctx.fillStyle = getRandomColor();
  } else if(y + dy > canvas.height-ballRadius) {
      if(x > paddleX && x < paddleX + paddleWidth) {
        dy = -dy;
      }
      else {
        alert("Game Over");
        document.location.reload();
      }
  }

  if(rightPressed && paddleX < canvas.width-paddleWidth) {
    paddleX += 7;
  }
  else if(leftPressed && paddleX > 0) {
    paddleX -= 7;
  }

  x += dx;
  y += dy;
}
setInterval(draw, 15);

@@ -496,16 +496,31 @@
 ks = %5B%5D;
+%0Avar score = 0;
 %0A%0Afor(c=
@@ -1251,17 +1251,16 @@
 ;%0A    //
- 
 ctx.fill
@@ -2451,27 +2451,338 @@
     
-%7D%0A      %7D%0A    %7D%0A  %7D
+  score++;%0A          if(score == brickRowCount*brickColumnCount) %7B%0A                        alert(%22You win!%22);%0A                        document.location.reload();%0A          %7D%0A        %7D%0A      %7D%0A    %7D%0A  %7D%0A%7D%0A%0Afunction drawScore() %7B%0A    ctx.font = %2216px Arial%22;%0A    ctx.fillStyle = %22#0095DD%22;%0A    ctx.fillText(%22Score: %22+ score, 8, 20);
 %0A%7D%0A%0A
@@ -2877,24 +2877,39 @@
 awPaddle();%0A
+  drawScore();%0A
   drawBricks
@@ -3251,24 +3251,66 @@
   dy = -dy;%0A
+        ctx.fillStyle = getRandomColor();%0A
       %7D%0A    

Add score