[Some bug ] Use class Syntax to Define a Constructor Function

[Some bug ] Use class Syntax to Define a Constructor Function


Tell us what’s happening:
Same issue as this post. [Some bug] Use getters and setters to Control Access to an Object

I only used the class keyword. Didn’t setup the constructor method at all.

It still passed the test.

Your code so far

function makeClass() {
  "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'

Your browser information:

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

Link to the challenge:

[Some bug] Use getters and setters to Control Access to an Object

Thank you so much for reporting issues. Hopefully this one easier to fix.

This is great people help people, just like you reported the issues. Really appreciate it.


It’s because the test cases are not written for the functionality of the program.


FYI the following two videos helped me learn constructors/this exercise:
A. https://www.youtube.com/watch?v=F3GeM_KrGjI
B. https://www.youtube.com/watch?v=f5wGZiYVfjk


I am still facing problems with the code. Please fix it.


What problems are you encountering? And what does your code look like?

And as an aside, unless your issue is related to this particular bug, it may make more sense to create a new thread for your issue.


class Vegetable {
constructor(Vegetable) {
this.Vegetable = Vegetable;

This is the code I have changed. It manages to pass all the other tests except
**this.carrot = carrot

where am I going wrong?


but it shouldn’t be this.carrot. It should be carrot.name.

You’re setting the property Vegetable to the value of the passed param, but that isn’t what the instructions say.

The Vegetable lets you create a vegetable object, with a property name , to be passed to constructor.

Thus, you’re shouldn’t be setting a property .Vegetable, you’re setting a property .name.


got it, Thanks!

My mistake: constructor(name) not constructor(Vegetable)


Well, and inside the constructor,

 this.name = name;