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.
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'
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'
Right, but that code is indeed passing the tests for the challenge, while that code should be failing. That should be filed as a bug @collinstommy, if it hasn’t already.
I’d say there is a bug in this assignment somewhere… I passed the assignment with this
"use strict";
/* Alter code below this line */
class Vegetable {
};
/* Alter code above this line */
return Vegetable;
}
const Vegetable = makeClass();
const carrot = new Vegetable('carrot');
console.log(carrot.name); // => should be 'carrot'```
Hi there! This is my first contribution to the community. I hope that my manners are proper ennough: I don’t live in a english speaking country.
So my question is…Why do we need wrapping the constructor inside a makeClass function and assignning it to the Vegetable variable? I’ve checked myself passing the test without this (just by removing the wrapping function and removing the assignment) and , not very surprisingly, tests went green.
function makeClass() {
"use strict";
/* Alter code below this line */
return class makeClass {
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'