Keep getting a TypeError on a project of my own

Hello!
I am working on a javascript project of my own which is а variation on the Codecademy project “Meal Maker” by adapting it to generate a random Shakespearean insult. I keep getting the following error message:

/home/ccuser/workspace/sandbox-node-14-6222663bbed11d26a368ec37/script.js:36
return this._columns[columnName].push(descriptor);
^

TypeError: Cannot read property ‘push’ of undefined
at Object.addDescriptorToColumn (/home/ccuser/workspace/sandbox-node-14-6222663bbed11d26a368ec37/script.js:36:38)

Below is my code
Thank you

const generator = {
  _columns: {
    firstAdjectives: [],
    secondAdjectives: [],
    nouns: []
  },
  get columns() {
    return {
      firstAdjectives: this.firstAdjectives,
      secondAdjectives: this.secondAdjectives,
      nouns: this.nouns
    }
  },
  get firstAdjectives(){

  },
  set firstAdjectives(firstAdjectivesIn) {

  },
  get secondAdjectives(){

  },
  set secondAdjectives(secondAdjectivesIn) {

  },  
  get nouns(){

  },
  set nouns(nounsIn) {

  },
  addDescriptorToColumn(columnName,descriptorName) {
    const descriptor = {
      name: descriptorName
    };
    return this._columns[columnName].push(descriptor);
  },
  getRandomDescriptorFromColumn: function(columnName) {
    const descriptors = this._columns[columnName];
    const randomIndex = Math.floor(Math.random() * descriptors.length);
    return descriptors[randomIndex];
  },
  generateRandomInsult() {
    const firstAdjective = this.getRandomDescriptorFromColumn('firstAdjectives');
    const secondAdjective = this.getRandomDescriptorFromColumn('secondAdjectives');
    const noun = this.getRandomDescriptorFromColumn('nouns');
    return `Thou ${firstAjective.name} ${secondAjective.name} ${noun.name}!`
  }
};

generator.addDescriptorToColumn('firstAjectives', "artless");


generator.addDescriptorToColumn('secondAjectives', "base-court");



generator.addDescriptorToColumn('nouns', "apple-john");

const meal = insult.generateRandomInsult()
console.log(insult)

Hello!
Notice how the property names in your columns() function are firstAdjectives and secondAdjectives (with a d). When you try to add descriptors to them here:

generator.addDescriptorToColumn('firstAjectives', "artless");


generator.addDescriptorToColumn('secondAjectives', "base-court");

Notice the argument is spelled without a d: secondAjective.

Of course, it’s a typo. It’s always a typo.

Again, thank you!

1 Like