6/7 Explanation


#1

Hi everyone. My code below passes but in the console I'm getting an error message of:

TypeError: StaffMember is not a constructor

Could someone explain this for me? Would be very appreciative:

// create a constructor for the StaffMember class
var StaffMember = new Object();
this.StaffMember.name = name;
this.StaffMember.discountPercent = 0;

var sally = new StaffMember("Sally",5);
var bob = new StaffMember("Bob",10);

//Create a StaffMember for yourself called me
var me = new StaffMember("me",20);

Thanks!


#2

@emmspete

Looks like you have not created the constructor properly:

// create a constructor for the StaffMember class
function StaffMember (name, discountPercent) {
this.name = name;
this.discountPercent = discountPercent;
}

var sally = new StaffMember("Sally",5);
var bob = new StaffMember("Bob",10);

//Create a StaffMember for yourself called me
var me = new StaffMember("John", 20);

You can check the correct syntax here:

http://www.w3schools.com/js/js_object_definition.asp

Please like my post if I have helped you. Thanks!