#1

What`s wrong ??

``````Replace this line with your code.
function StaffMember(name,discountPercent){
this.name = name;
this.discountPercent = discountPercent;
}

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

var cashRegister = {
total:0,
lastTransactionAmount: 0,
this.total += (itemCost || 0);
this.lastTransactionAmount = itemCost;
},
scan: function(item,quantity){
switch (item){
case "eggs": this.add(0.98 * quantity); break;
case "milk": this.add(1.23 * quantity); break;
case "magazine": this.add(4.99 * quantity); break;
case "chocolate": this.add(0.45 * quantity); break;
}
return true;
},
voidLastTransaction : function(){
this.total -= this.lastTransactionAmount;
this.lastTransactionAmount = 0;
},
applyStaffDiscount: function(employee){
this.total = (this.total -= (this.total * employee.discountPercent/100));
}
};

cashRegister.scan('eggs',1);
cashRegister.scan('milk',1);
cashRegister.scan('magazine',3);
// Apply your staff discount by passing the 'me' object
// to applyStaffDiscount
cashRegister.applyStaffDiscount("me");

// Show the total bill

#2

NaN means the value is undefined or can't be represented, for example the result of division by zero.
You need to find out what operation produced the value, it was probably doing something nonsensical.

#3

it is due to the value "employee.discountPercent". It is undefined as the variable employee does not has a property as discountPercent. Can anyone help how to access it?

#4

Can't access what isn't there. Put it there or access something else. (ask yourself what you intend to do)
And if it's supposed to be there, then you would need to look at the part that would have put it there.
Your employee variable, have you considered what type of object that is and what it is supposed to be? When running your code, it is a string.

#5

The reason you got NaN (not a number) is because you are passing the string "me" to the method applyStaffDiscount. As a string is not a number when you apply the method (which expects a number) to the string you will get NaN. You need to pass the object me to the method.
i.e.
cashRegister.applyStaffDiscount(me);
not
cashRegister.applyStaffDiscount("me");

#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.