Items totaling NaN
<p>I'm working on a codecademy.com tutorial where we're building a cash register. I'm supposed to make the necessary tools to void a last transaction of the cash register. Therefore, I added </p>

<ol>
<li>a property called lastTransactionAmount</li>
<li>a further line of code to the function 'add' to set the last transaction amount</li>
<li>a function voidLastTransaction amount that subtracts the last transaction from the total</li>
<li>then I tested the void last transaction function at the bottom (which I expect to void the four chocolates</li>
<li>then I tried to add three chocolates</li>
</ol>

<p>When I run the code, I get</p>

<blockquote>
  <p>Your bill is NaN</p>
</blockquote>

<p>Can someone explain what I'm doing wrong? </p>

<pre><code>var cashRegister = {
    total:0,
    //Dont forget to add your property
    lastTransactionAmount: 0,         //this is a property I added

    add: function(itemCost) {
        this.total +=  itemCost;
        this.lastTransactionAmount = this.itemCost; //I added this to save 
    },
    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 // I made this function to void l
    voidLastTransaction: function() {
        this.total = 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.voidLastTransaction();              //I'm voiding last transaction
cashRegister.scan('chocolate', 3);             //trying to add 3 (instead of 4)chocolate

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