Use class Syntax to Define a Constructor(Error) Function

Tell us what’s happening:

I am trying to solve this challenge, but when I run the code i get the following error:

Cannot set property ‘name’ of undefined

Can anybody suggest anything?

Your code so far


function makeClass() {
  "use strict";

  var carrot;
  carrot.name="carrot";
  return message
}

const Vegetable = makeClass()

const carrot = new Message("creating new Ball")
console.log(carrot.name)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 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/

So your challenge is for you to create a class within the makeClass function.

You used var, which is to define a variable not a class. I suggest you read over the challenge again throughly and try to understand what are classes as well as look at the examples that they give you.