function Player(color, startingPos, startingDirection, keyBindings) {
  this.color       = color;
  this.trail       = [ startingPos ];
  this.direction   = startingDirection;
  this.keyBindings = keyBindings;
}

Player.prototype.move = function(game) {
  var nextPos = this.newPos();
  game.detectCollision(nextPos);

  if (game.end === false) {
    this.trail.push(nextPos);
    this.colorize(game);
  }
};

Player.prototype.newPos = function() {
  var xPosition = this.trail[this.trail.length - 1].x;
  var yPosition = this.trail[this.trail.length - 1].y;

  switch(this.direction) {
    case "right":
      xPosition++;
      break;
    case "left":
      xPosition--;
      break;
    case "up":
      yPosition--;
      break;
    case "down":
      yPosition++;
      break;
  }

  return { x: xPosition, y: yPosition };
};

Player.prototype.colorize = function(game) {
  var lastPos = this.trail[this.trail.length - 1];

  function hexToRgb(hex) {
    var resultObj = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
    var result = resultObj ? {
      r: parseInt(resultObj[1], 16),
      g: parseInt(resultObj[2], 16),
      b: parseInt(resultObj[3], 16)
    } : null;

    return (result.r + "," + result.g + "," + result.b);
  }
  debugger;
  game.board.fillStyle = "rgba(" + hexToRgb(this.color) + ", 0.5)";
  game.board.fillRect(lastPos.x*10, lastPos.y*10, 10, 10);
};

Player.prototype.changeDirection = function(key) {
  if (key == this.keyBindings.left && this.direction != "right") {
    this.direction = "left";
  } else if (key == this.keyBindings.up && this.direction != "down") {
    this.direction = "up";
  } else if (key == this.keyBindings.right && this.direction != "left") {
    this.direction = "right";
  } else if (key == this.keyBindings.down && this.direction != "up") {
    this.direction = "down";
  }
};

module.exports = Player;

@@ -924,340 +924,8 @@
  1%5D;
-%0A%0A  function hexToRgb(hex) %7B%0A    var resultObj = /%5E#?(%5Ba-f%5Cd%5D%7B2%7D)(%5Ba-f%5Cd%5D%7B2%7D)(%5Ba-f%5Cd%5D%7B2%7D)$/i.exec(hex);%0A    var result = resultObj ? %7B%0A      r: parseInt(resultObj%5B1%5D, 16),%0A      g: parseInt(resultObj%5B2%5D, 16),%0A      b: parseInt(resultObj%5B3%5D, 16)%0A    %7D : null;%0A%0A    return (result.r + %22,%22 + result.g + %22,%22 + result.b);%0A  %7D%0A  debugger;
 %0A  g
@@ -1509,16 +1509,318 @@
   %7D%0A%7D;%0A%0A
+function hexToRgb(hex) %7B%0A  var resultObj = /%5E#?(%5Ba-f%5Cd%5D%7B2%7D)(%5Ba-f%5Cd%5D%7B2%7D)(%5Ba-f%5Cd%5D%7B2%7D)$/i.exec(hex);%0A  var result = resultObj ? %7B%0A    r: parseInt(resultObj%5B1%5D, 16),%0A    g: parseInt(resultObj%5B2%5D, 16),%0A    b: parseInt(resultObj%5B3%5D, 16)%0A  %7D : null;%0A%0A  return (result.r + %22,%22 + result.g + %22,%22 + result.b);%0A%7D%0A%0A
 module.e

Move hexToRgba to a function outside of colorize method