Bleep Bleep


#1

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;
    },
    //Add the voidLastTransaction Method here
    voidLastTrasaction: 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.voidLastTrasaction();
cashRegister.scan('chocolate',3);
//Show the total bill
console.log('Your bill is '+cashRegister.total);

//Please help me to solve this problem


#2

Hi,

I have done all but it is not allowing to clear this stage.


#3

the method should be named voidLastTransaction. you have a slightly typo in it

this goes for both the method declaration and method call


#4

I made changes but it is not resolving.


#5

What is the problem to begin with?


#6

I have code for the bleep program and it showing output but i dont what is the expect output. It throws try again false output.


#7

Can you find out what the expected output is? It scans a few prices and voids something, run that on a calculator and then compare, right?


#8

//Void the last transaction and then add 3 instead

What the about exactly means?


#9

Void in this context means roughly the same as invalidate, so you would undo it


#10

can i see an updated version of your code?


#11

var cashRegister = {
total:0,
LastTransactionAmount: 0, // Try changing this to lastTransactionAmount

voidLastTrasaction: function(){ // Try changing this to voidLastTransaction
this.total -= this.LastTransactionAmount; // Try changing this to this.lastTransactionAmount

cashRegister.voidLastTrasaction(); // Try changing this to cashRegister.voidLastTransaction();


#12

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;
    },
    //Add the voidLastTransaction Method here
    voidLastTransaction: function() {
        this.total -= 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.voidLastTransaction();
cashRegister.scan('chocolate', 3);
//Show the total bill
console.log('Your bill is '+cashRegister.total);

It tells me "ReferenceError: lastTransactionAmount is not defined", and I checked for typos: none. What am I doing wrong?


#13

here:

this.lastTransactionAmount = itemCost;

you add lastTransactionAmount to this so you can access this variable in other methods, if you want to do so, you have to use this.lastTransactionAmount


#14

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