7. You deserve it!


#1

function StaffMember(name,discountPercent){
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 StaffMember = new StaffMemeber("Tyler",20)

var cashRegister = {
total:0,
lastTransactionAmount: 0,
add: function(itemCost){
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;
},
// Create a new method applyStaffDiscount here
applyStaffDiscount : function (employee) {
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
console.log('Your bill is '+cashRegister.total.toFixed(2));

it says unexpected identifier, but I'm pretty sure that I did it right


#2

I don't see "toFixed( parameter )" anywhere in your code. You're going above and beyond in this lesson so I know you're a smart guy, I hope my hint is enough to get you on the right track


#3

I know you are talking about the void transaction function, but idk what the param. would be


#4

and nah man, Im not smart with JS. I always need help with figuring out the simplest code


#5

That's quite alright sir, I'm the same way in the early stages, but you've got a decent grasp on it, just remove .toFixed(2) and see what happens, I may be misreading your code, but as far as errors are concerned they look mostly like logic errors instead of script errors.

Try that and we'll work from there.


#6

It still says unexpected identifier


#7

And I didnt get ALL the code by myself, I had to copy some of it which I feel bad about. Im mostly a auditory learner and not a visual one...which is why I have a hard time grasping the concept of learning JS


#8

And I realized that there's actually a tofixed thing in the bottom of the code XD


#9

Around line 10 you have member spelled wrong, should not be StaffMemeber("Tyler" etc.

That might be the unexpected identifier.


#10

I tried that, But it still doesnt work


#11

i figured out 3 mistakes. after correcting them your code worked perfectly. check out.

  1. "

it should be "StaffMember".

2.you have not closed the applyStaffDiscount method with coma
3. haven't closed the cashRegister object at end after closing the applyStaffDiscount method.

code should be as shown below
// Create a new method applyStaffDiscount here
applyStaffDiscount : function (employee) {
this.total -= this.total * (employee.discountPercent/100);

},
};


#12

Don't know if you fixed it but you called your variable "StaffMember"

and called "me"


#13

Ya, I changed it the variable name to me and passed it and did the changes that malik suggested but it still says unexpected token. here's my code:

function StaffMember(name,discountPercent){
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("Tyler",20);

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


#14

Hi so I was having a syntax error on this but your latest code is almost identical to mine when it passed... my experience is that codecademys environment and debugger is horrible if it's not exact (I.e. in my case previously i actually coded a more efficient way to run the the scan but it wouldn't pass it because it wasn't exact) try moving the colon on your applyStaffDiscount method to look like this

applyStaffDiscount: function (employee) {
this.total -= this.total * (employee.discountPercent/100);

},

and if it fails try refreshing the page to clear the environment and resubmit your code


#15

You do not need a comma after 100);} in your code. Here is your code:
this.total -= this.total * (employee.discountPercent/100);

},
};

cashRegister.scan('eggs', 1);

Here is my version which worked:
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("Alfalfa",20);

var cashRegister = {
total:0,
lastTransactionAmount: 0,
add: function(itemCost){
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;
},
// Create a new method applyStaffDiscount here
applyStaffDiscount : function(employee){
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
console.log('Your bill is '+cashRegister.total.toFixed(2));


#16

//This code works

function StaffMember(name,discountPercent){
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("me",20);

var cashRegister = {
total:0,
lastTransactionAmount: 0,
add: function(itemCost){
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;
},
// Create a new method applyStaffDiscount here
applyStaffDiscount : function(employee){
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
console.log('Your bill is '+cashRegister.total.toFixed(2));