7. Can't Figure out what's wrong-unexpected token error


#1

I am stuck and getting constantly this "unexpected token" error. I am quite sure about the code but this little syntax error is driving me nuts. Can you guys help me out here with my error? I just can't make any progress

function StaffMember(name,discoutPercent){
    this.name = name;
    this.discountPercent = discountPercent;
}

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

// Create yourself again as 'me' with a staff discount of 20%
var me = new StaffMember("Baran",20);

var cashRegister = {
    total:0,
    lastTransactionAmount: 0,
    add: function(itemCost){
        this.total += itemCost;
        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;
    };
    // Create a new method applyStaffDiscount here
    applyStaffDiscount : function() {
       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
applyStaffDiscount('me');

// Show the total bill
console.log('Your bill is '+cashRegister.total.toFixed(2));

#2

to start here:

    add: function(itemCost){
        this.total += itemCost;
        this.lastTransactionAmount = itemCost;
    };

the }; is wrong, to separate the methods in the object this should be },

then here:

applyStaffDiscount('me');

this is a method of an object so you need the following syntax:

objectName.methodName()

objectName is missing in your case

There are more problems, but i am still looking


#3

the void method has the same problem:

voidLastTransaction : function(){
        this.total -= this.lastTransactionAmount;
        this.lastTransactionAmount = 0;
    };

the }; should be },, same for scan and applyStaffDiscount.

then here:

applyStaffDiscount('me');

me refers to this variable:

var me = new StaffMember("Baran",20);

so it should be without apostrophes:

applyStaffDiscount(me);

are you still sure? i already found > 5 mistakes, and there seems to be more


#4

I have just gone through the syntax errors and calling the applyStaffDiscount method issue and I'm through. Thank you for your help.


#5