old_contents: const sayHello = function() { console.log('Hello'); };
  
  sayHello();
  
  
  $(document).ready(function(){
    var canvas = document.getElementById('game');
    var ctx = canvas.getContext("2d");
    var w = $(canvas).width();
    var h = $(canvas).height();
  
    ctx.fillStyle = "black";
    ctx.fillRect(0, 0, w, h);
  
    var d;
  
    var player1;
  
    function init()
    {
  
      d = "right"; //default direction
      createPlayer();
  
      $(document).keydown(function(e){
        var key = e.which;
  
        if(key == "37" && d != "right") d = "left";
        else if(key == "38" && d != "down") d = "up";
        else if(key == "39" && d != "left") d = "right";
        else if(key == "40" && d != "up") d = "down";
      });
  
      //Lets move the snake now using a timer which will trigger the paint function
      //every 60ms
      if(typeof gameLoop !== "undefined") clearInterval(gameLoop);
      window.gameLoop = setInterval(paint, 30);
    }
  
    init();
  
    function createPlayer()
    {
      var length = 1; //Length of the snake
      player1 = []; //Empty array to start with
  
      for(var i = length; i < 5; i++)
      {
        player1.push({x: i, y:0});
      }
    }
  
    function paint()
    {
      var nx = player1[player1.length - 1].x;
      var ny = player1[player1.length - 1].y;
  
      if(d == "right") nx++;
      else if(d == "left") nx--;
      else if(d == "up") ny--;
      else if(d == "down") ny++;
  
      if(nx == -1 || nx == w/10 || ny == -1 || ny == h/10)
      {
        init();
  
        return;
      }
  
      player1.push({x: nx, y: ny});
  
      for(var i = 0; i < player1.length; i++)
      {
        var c = player1[i];
  
        ctx.fillStyle = "red";
        ctx.fillRect(c.x*10, c.y*10, 10, 10);
      }
    }
  
  });
  
  
new_contents: $(document).ready(function(){
  
    var canvas    = document.getElementById('game');
    var gameBoard = canvas.getContext("2d");
    var width     = $(canvas).width();
    var height    = $(canvas).height();
  
    gameBoard.fillStyle = "black";
    gameBoard.fillRect(0, 0, width, height);
  
    function Player(color, startingX, startingY, startingDirection) {
      this.color     = color;
      this.trail     = [[startingX, startingY]];
      this.direction = startingDirection;
    }
  
    Player.prototype.move = function() {
      var xPosition = this.trail[this.trail.length - 1][0];
      var yPosition = this.trail[this.trail.length - 1][1];
  
      switch(this.direction) {
        case "right":
          xPosition++;
          break;
        case "left":
          xPosition--;
          break;
        case "up":
          yPosition--;
          break;
        case "down":
          yPosition++;
          break;
      }
  
      detectCollision(xPosition, yPosition);
      this.trail.push([xPosition, yPosition]);
      colorizePlayers()
    };
  
    function colorizePlayers() {
      for(var i = 0; i < playerOne.trail.length; i++)
      {
        var el = playerOne.trail[i];
  
        gameBoard.fillStyle = playerOne.color;
        gameBoard.fillRect(el[0]*10, el[1]*10, 10, 10);
      }
    }
  
    function detectCollision(xPosition, yPosition) {
      if(xPosition == -1 || xPosition == 1200/10 || yPosition == -1 || yPosition == 600/10)
      {
        clearInterval(window.gameLoop);
        endGame();
      }
    }
  
    function endGame() {
      alert("Player one loses! Press enter to play again");
      location.reload();
    }
  
    function movePlayers() {
      playerOne.move();
    }
  
    function startGame()
    {
      window.playerOne = new Player("red", 0, 0, "right");
  
      playerOne.move();
  
      $(document).keydown(function(e){
        var key = e.which;
  
        if(key == "37" && playerOne.direction != "right")
          playerOne.direction = "left";
        else if(key == "38" && playerOne.direction != "down")
          playerOne.direction = "up";
        else if(key == "39" && playerOne.direction != "left")
          playerOne.direction = "right";
        else if(key == "40" && playerOne.direction != "up")
          playerOne.direction = "down";
      });
  
      window.gameLoop = setInterval(movePlayers, 30);
    }
  
    startGame();
  });
  
  
subject: Add endgame feature which will pop an alert after a crash and will restart after pressing enter