Use class Syntax to Define a Constructor Function

Use class Syntax to Define a Constructor Function
0.0 0

#1

Where is error ? :confused:

Your code so far


function makeClass() {
  "use strict";
  /* Alter code below this line */
  class Vegetable {
    constructor(vegetable){
      return this.vegetable;
    }
  }
  /* Alter code above this line */
}
const Vegetable = makeClass();
const carrot = new Vegetable('carrot');
console.log(carrot.name); // => should be 'carrot'

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-class-syntax-to-define-a-constructor-function


#2

You need to pass in the vegetable name. The constructor is used to set up the object. I shouldn’t actually return anything. You need to change this.vegatable to this.name as the test is looking for a name property to be set:

function makeClass() {
  "use strict";
  /* Alter code below this line */
  class Vegetable {
    constructor(name){
      this.name = name;
    }
  }
  /* Alter code above this line */
  return Vegetable;
}
const Vegetable = makeClass();
const carrot = new Vegetable('carrot');
console.log(carrot.name); // => should be 'carrot'

#3

thank you so much…:+1:t2:


#4

I’ve passed the challenge with this code :man_shrugging:t2: :slight_smile:

function makeClass() {
  "use strict";
  /* Alter code below this line */
  class Vegetable {
    constructor () {
      
    }
  }
  /* Alter code above this line */
  return Vegetable;
}
const Vegetable = makeClass();
const carrot = new Vegetable('carrot');
console.log(carrot.name); // => should be 'carrot'