7. You Deserved It!


Don't seem to know why it won't accept my solution though the answer is correct.("Your bill is 13.74")

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("Anmol",20)

var cashRegister = {
    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){

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

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


changed my applyStaffDiscount method and it worked for me.
But still don't get why it did'nt work earlier


Well, your code is correct.

One of the tests codecademy uses to check if your code is correct is to check value of cashRegister.total. In your case it is 13.744000000000002 and codecademy expects it to be 13.744.

Does it make any difference? Not in this script. Why is there a difference? This is kind of more complicated topic and the explanation might be useless for you. Basically speaking, computers use a special representation of real numbers, representation indicates that this is only an approximation of the real value. So for example, we can know that the correct result of some calculations is 13.5, but the same calculations made by computer might result in a slightly different value - 13.500000000000001 (for example).

So don't worry, your code is correct and that is a really good solution. Author of the course simply didn't foreseen this situation.


Alright. So basically I can't do anything about it. Thanks for helping me out.


You're very welcome :slight_smile:

Yes, because that was not your fault. We could post a bug report, but this course is not a priority for the codecademy so it probably would not be fixed anyway.


I was able move forward by subtracting .000000000000002 from the total in the apply discount method.

applyStaffDiscount : function(employee){
    this.total -=.000000000000002;

the last section will remove the trailing numbers before being judged by the Machine, allowing me to continue the exercises.


What changes did you make??


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