Your bill is NaN


What`s wrong :frowning: ??
Your bill is NaN

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

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

var cashRegister = {
    lastTransactionAmount: 0,
    add: function(itemCost){ += (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.lastTransactionAmount;
        this.lastTransactionAmount = 0;
    applyStaffDiscount: function(employee){ = ( -= ( * employee.discountPercent/100));

// Apply your staff discount by passing the 'me' object 
// to applyStaffDiscount

// Show the total bill
console.log('Your bill is ';


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.


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?


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.


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.


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