Tell us what’s happening:
I managed to pass this test with the following code but still, I don’t know how this code works![]()
I have two questions, please explain to me if you can.
1)What is the purpose of using makeClass() function here? and Why we are assigning it to const Vegetable?
2)How does constructor() works? and what does the following code indicates?
constructor(name)
{
this.name=name;
}
Your code so far
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'
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.
Link to the challenge: