Cannot read property 'x' of undefined : <p>So I have been trying to put together a simple little text based RPG and I just finished creating objects for the buttons and the different types of characters. When I stopped for the day and saved, I had no errors, but I came back on today and received the error "Cannot read property 'x' of undefined." The error had no lines of code listed, and I had no errors listed other than that. I only have used 'x' in the Button object so I assume the issue is somewhere in this block of code:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>//selection buttons
var Button = function(config) {
  this.x = config.x || 5;
  this.y = config.y || 2;
  this.width = config.width || 390;
  this.height = config.height || 96;
  this.vrtx = config.vrtx || 50; //curve on the corners
  this.lable = config.lable || "Click Here";
  this.r = config.r || 100;
  this.b = config.b || 100;
  this.g = config.g || 100;
};

Button.prototype.draw = function() {
  strokeWeight(5);
  stroke(this.r / 2, this.b / 2, this.g / 2);
  fill(this.r, this.b, this.g);
  rect(this.x, this.y, this.width, this.height, this.vrtx);
  fill(0, 0, 0);
  textSize(27);
  textAlign(LEFT, TOP);
  text(this.label, this.x + 10, this.y + this.height / 4);
};

var btn1 = new Button( /*customize button*/ );</code></pre>
</div>
</div>
</p>

<p>Just incase it isn't in that section, here i the rest of the code:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>//classes
var mage;
var warrior;
var rogue;
var cleric;
//stats
var manaLvl;
var strengthLvl;
var stealthLvl;
var xpLvl = 10;
var enemyCount = 0; //# of enemies defeted
var lvl; //player's level

//player stats and level up
var character = function(health, armour, packSize, packItems, mana, strength, stealth, xp) {
  this.health = health;
  this.defArmour = armour;
  this.packSize = packSize;
  this.packItems = packItems;
  this.mana = mana;
  this.strength = strength;
  this.stealth = stealth;
  this.xp = xp;
};

Character.prototype.lvlUp = function() {
  this.health += 2;
  this.packSize += 1;
  this.mana += manaLvl;
  this.strength += strengthLvl;
  this.stealth += stealthLvl;
  enemyCount = 0;
};

character.prototype.xpGain = function() {
  this.xp = enemyCount * xpLvl;
  if (this.xp === 100) {
    character.lvlUp();
  }
};

character.prototype.packStorage = function() {
  if (this.packItems &lt; this.packSize) {
    //allow player to store items
  }
};

//selection buttons
var Button = function(config) {
  this.x = config.x || 5;
  this.y = config.y || 2;
  this.width = config.width || 390;
  this.height = config.height || 96;
  this.vrtx = config.vrtx || 50; //curve on the corners
  this.lable = config.lable || "Click Here";
  this.r = config.r || 100;
  this.b = config.b || 100;
  this.g = config.g || 100;
};

Button.prototype.draw = function() {
  strokeWeight(5);
  stroke(this.r / 2, this.b / 2, this.g / 2);
  fill(this.r, this.b, this.g);
  rect(this.x, this.y, this.width, this.height, this.vrtx);
  fill(0, 0, 0);
  textSize(27);
  textAlign(LEFT, TOP);
  text(this.label, this.x + 10, this.y + this.height / 4);
};

var btn1 = new Button( /*customize button*/ );

//class selection
if (mage === true) {
  var lvl = new character(10, 5, 10, 20, 5, 5);
  manaLvl = 3;
  strengthLvl = 1;
  stealthLvl = 1;
} else if (warrior === true) {
  var lvl = new character(20, 20, 5, 20, 5, 5);
  manaLvl = 1;
  strengthLvl = 3;
  stealthLvl = 1;
} else if (rogue === true) {
  var lvl = new character(15, 10, 10, 20, 5, 5);
  manaLvl = 1;
  strengthLvl = 2;
  stealthLvl = 2;
} else if (cleric === true) {
  var lvl = new character(15, 10, 15, 5, 10, 15);
  manaLvl = 2;
  strengthLvl = 2;
  stealthLvl = 1;
}

var draw = function() {
  btn1.draw();
};</code></pre>
</div>
</div>
</p>

<p>If anyone knows what the issue is I would be very thankful for your help!</p>
