title: How to create calculations in alerts?
body: <p>I am creating an interactive game and am very new to programming.  I was wondering how exactly to increment a variable and then put it into an alert box. I want to find the calculation of foodCaught and foodWasted and display it in an alert box at the end of my game. Also how do I make it so it is on a timer and at the end of this timer the alert box with foodCaught and foodWasted appears? </p>
  
  <pre><code>$(document).ready(function(){
      var cnv = $("#myCanvas")[0];
      var ctx = cnv.getContext("2d");
      var catcherX = ctx.canvas.width/2;
      var catcherY = ctx.canvas.height - 100; // set the initial location of the catcher's y position
      var numFoods = 5;
      var catcherSpeed = 30;
      var foodCaught = 0;
      var foodWasted = 0;
  
      function Food(){ // the name of the constructor usually begins with a captial letter
          this.radius = 30;
  
          this.x = Math.floor(Math.random()*ctx.canvas.width);
          this.y = 0 - this.radius;
          this.speed = 1+ Math.floor(Math.random()*5);
          var imageToUse = new Image();
          this.width = 50; // default values
          this.height = 50; // default values
  
          var randomNum = Math.floor(Math.random()*2); // create a random number to choose the image
          if(randomNum == 0){
  
              imageToUse.src = "corn.png";
              this.width = 27; // width of corn.png
              this.height = 100; // height of corn.png
  
          } else if(randomNum == 1){
              imageToUse.src = "straw.png"
              this.width = 83; // width of straw.png
              this.height = 100; // height of straw.png
          }
  
          this.moveFood = function(){
  
              if(this.y &gt; ctx.canvas.height){
                  this.x =  Math.floor(Math.random()*ctx.canvas.width);
                  this.y = 0;
                  footWasted += 1;
              }
  
              this.y += this.speed; // add speed to location
          }
  
          this.drawFood = function() {
              ctx.drawImage(imageToUse, this.x, this.y);
          }
  
          this.intersectFood = function(targetX, targetY, targetR) {
  
              if(this.x + this.width &gt; targetX &amp;&amp; this.x &lt; targetX + targetR &amp;&amp; this.y + this.height &gt; targetY &amp;&amp; this.y &lt; targetY + targetR){
                  foodCaught += 1;
                  return true;
              }
  
              /*
              var distanceX = this.x - targetX;
              var distanceY = this.y - targetY;
              var distance = Math.sqrt(distanceX * distanceX + distanceY * distanceY);
  
              if(distance &lt; targetR + this.radius){
                  return true;
              }
               */
          }
      }
      // create an Array of Foods
      var FoodArray = new Array();
      for(var i=0; i&lt;numFoods; i++) {
          FoodArray[i] = new Food();
      }
  
      // get mouse Postion
  
      $(document).keydown(function(e){ // attach the event to the entire document
  
          switch(e.keyCode){
              case 37:    // left
                  catcherX-= catcherSpeed;
                  break;
              case 39:    // right
                  catcherX+= catcherSpeed;
                  break;
          }
  
      });
  
      var interval = setInterval(gameLoop,10); // call draw every 10 milliseconds
      var counter = 0;
  
      function gameLoop(){
          ctx.clearRect(0,0, ctx.canvas.width, ctx.canvas.height); //clears previous circles
          for(var i=0; i &lt; FoodArray.length; i++) {
              FoodArray[i].moveFood();
              FoodArray[i].drawFood();
              if(FoodArray[i].intersectFood(catcherX, catcherY, 15)){
                  FoodArray.splice(i,1);
                   console.log(i);
              }
          }
  
          // draw catcher
          ctx.beginPath();
          ctx.fillStyle="#119933";
          ctx.arc(catcherX,catcherY,15,0,Math.PI*2,true);
          ctx.closePath();
          ctx.fill();
  </code></pre>