5. Bleep Bleep Oops try again


#1

I really dont know whats wrong...i saw other similar posts but i cant find the problem.


var cashRegister = {
    total:0,
    lastTransactionAmount:0,

    add: function(itemCost) {
        this.lastTransactionAmount = itemCost;
        this.total +=  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;
    }
    
};

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


cashRegister.voidLastTransacation;
cashRegister.scan('chocolate', 3);


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


#2

this line:

lastTransactionAmount:0,

is not needed, you can't void a transaction before buying an item.

here:

cashRegister.voidLastTransacation;

voidLastTransaction is a method, to call a method you need to use parentheses, her is the general syntax:

objectName.methodName()

you also misspelled voidLastTransaction here, make sure to check the spelling

If you need more help, post an updated version of your code


#3

wow......i even looked for wrong spellings....but obviously im fuckin blind...thanks


#4

use the IDE (intergrated developers environment) to your advantage. If you select a variable (double click), everywhere they get surrounded by a box:

see how cashRegister has a box around it? If you have a spelling mistake, the box will now show, it only works for exact matches

makes searching for typos a lot easier


#5

y thx...forgot about it ....:expressionless:


#6

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