Bleep Bleep; Am I not understanding the lessson properly?


#1

Am I not understanding the requirement properly? When the request is to remove the last transaction. Is it asking to remove the last quantified transaction, aka say I bought 4 apples; removing the quantified transaction would be remove the the cost of 4 apples Or is the requirement to remove the last non-quantified transaction aka if you bought 4 apples, just remove 1 app. I think the latter is applied since the amount of items bought was never known to the ADD function to to begin with. I followed the (remove the last transaction aka, the last transaction was 1 chocolate, since the last purchase was 4 chocolates. If the goal was to remove 1 chocolate, and then add 3 chocolates back, I tested my code and it worked, I even posted alerts as the values generated. Please clear this up:

MY CODE:

var cashRegister = {
total:0,
//Dont forget to add your property
add: function(itemCost,am) {
this.am = am;
this.lastTransactionAmount = itemCost/am;
this.total += itemCost;
},
scan: function(item,quantity) {
this.quantity = quantity;
switch (item) {
case "eggs": this.add(0.98 * quantity,quantity); break;
case "milk": this.add(1.23 * quantity,quantity); break;
case "magazine": this.add(4.99 * quantity,quantity); break;
case "chocolate": this.add(0.45 * quantity,quantity); break;
}
return true;
},
//Add the voidLastTransaction Method here
voidLastTransactionAmount: function(){
this.total -= this.lastTransactionAmount;
alert("TOTAL COST QUANTIFIED AFTER SUBTRACTING 1 CHOCOLATE: " + this.total);
}
};

cashRegister.scan('eggs',1);
cashRegister.scan('milk',1);
cashRegister.scan('magazine',1);
cashRegister.scan('chocolate',4);
//test
alert("[quantified] total cost before subtracting 1 chocoloate: " + cashRegister.total + " || LAST TRANSACTION [NOT QUAUNTIFIED] aka 1 chocolate: " + cashRegister.lastTransactionAmount);

//Void the last transaction and then add 3 instead
cashRegister.voidLastTransactionAmount();
//SCAN THREE MORE CHOCOLATES
cashRegister.scan('chocolate',3)
alert("[quantified total] after adding 3 more chocolates: " + cashRegister.total);

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


#2

Not as instructed. The method is to take ONE parameter, itemCost. The total cost is sent as an argument in the call: add(0.45 * quantity).

There is no need whatever to give the variable a context. It is an argument.

case "eggs": this.add(0.98 * quantity,quantity); break;
case "milk": this.add(1.23 * quantity,quantity); break;
case "magazine": this.add(4.99 * quantity,quantity); break;
case "chocolate": this.add(0.45 * quantity,quantity); break;

Not as instructed.

The last transaction will be the total amount, 0.45 * 4. Voiding subtracts 1.80 from the total.

I'm still trying to figure out what your point is in this topic.


#3

I had not point, I had a question.


#4

This was my original code before all the extras I placed in which I posted in this thread; maybe I should have pasted both code sets to compare, but this still does not work.

1.What am I missing?
2. The error I get is "Oops, try again. false;" how does this help a student in fixing the code?

var cashRegister = {
    total:0,
    //Dont forget to add your property
    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;
    },
    //Add the voidLastTransaction Method here
    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)

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

#5

Remember to define the lastTransactionAmount property just below total: 0,


#6

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