Beep Beep, desired outcome, still wont pass


#1



I think my code is working, but it doesn't pass the lesson. I even added some console.logs() to make things a bit more clear when it wasn't working.

Error that I get: Oops, try again. false


var cashRegister = {
    total:0,
    //Dont forget to add your property
    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;
    },
    VoidLastTransactionAmount: function(){
        this.total -= this.lastTransactionAmount;
        console.log("last item Cost (" + this.lastTransactionAmount + ") voided");
    },
};

cashRegister.scan('eggs',1);
cashRegister.scan('milk',1);
cashRegister.scan('magazine',1);
cashRegister.scan('chocolate',4);

//Void the last transaction and then add 3 instead
cashRegister.VoidLastTransactionAmount();

cashRegister.scan('chocolate',3);

console.log('Your bill is '+cashRegister.total);


#2

The expected method name is, voidLastTransaction.


#3

changed both instances of VoidLastTransactionAmount to voidLastTransactionAmount
*still fails


#4

Will look some more. One moment, please...

Not that it will matter, but for the sake of clarity, define your lastTransactionAmount just under total. It won't fix anything, but it is a better practice to initialize variables.

Not asked for and not expected. Best remove that line so the SCT has less to squawk over.

Still looking... Nothing more found that looks to be a problem.


#5

Some updates. But not passing...
thanks for spending the time mtf, I'll check back in here in a while to see if you or anyone else found anything.

var cashRegister = {
    total:0,
    lastTransactionAmount:0,
    //Dont forget to add your property
    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;
    },
    voidLastTransactionAmount: function(){
        this.total -=this.lastTransactionAmount;
    },
};

cashRegister.scan('eggs',1);
cashRegister.scan('milk',1);
cashRegister.scan('magazine',1);
cashRegister.scan('chocolate',4);

//Void the last transaction and then add 3 instead
cashRegister.voidLastTransactionAmount();

cashRegister.scan('chocolate',3);

console.log('Your bill is '+cashRegister.total);

#6

To repeat, "The expected method name is, voidLastTransaction."


#7

ErmaGerd.
Thanks changing the Method name fixed it.


#8

For our own purposes, a name is a name is a name. The SCT doesn't have a very large set of comparison matches so we're forced to comply with the instructions. Glad you got it solved. Now on to jQuery?


#9

I think JQuery is next indeed! but I also might re-do JavaScript on the new page CA created since they are going to take this lesson series down. Lots of practice to become very fluent, I'm also sure there are a few important updates in there.


#10

I'm an old fart, so retaking a course is like seeing the same movie again. After a few months I pretty much forget the plot so it's like watching it for the first time. Programming can be like this, too. Until you really get into the kitchen with steady hands-on, the material falls away rapidly. Re-doing, review, experimentation, reading and re-reading are all a part of helping it to sink in. I'm pretty sure I've done the JS track half a dozen times, by now, and still find new ways to tackle the seemingly simple lessons.


#11

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