Building a Cash Register 4/7


#1

So, yeah, I know a little about programming in languages other than Javascript. I asked a question earlier about using an Object instead of a switch. and while faster, yes, I always program with foresight. I did a similar thing here, and it broke again. Instead of adding "* quantity" to every this.add in the switch, I used a for loop:

  scan: function(item,quantity) {
    for(i = 0; i < quantity;i++){
      switch (item) {
        case "eggs": this.add(0.98); break;
        case "milk": this.add(1.23); break;
        case "magazine": this.add(4.99); break;
        case "chocolate": this.add(0.45); break;
      }
    }
  }

thinking that, if I had 1000s of items, I could enclose the switch in a for loop and not have to add quantity to each case. While I achieve the same effect, The page won't let me progress with this code. Is there a reason that "Oops, try again. It doesn't seem like your 'quantity' actually works!" even though I get the right result? ( I do understand that for large quantities, there's a lot more flops.)


#2

@rshinra,
In the add Method you are adding itemCost to the total.

The itemCost is the product of the "eggs-price" multiplied by the quantity.....

The construct is for somebody sitting at the cash-Register in a supermarket
scanning each product and giving the quantity....

What is your story.....????


#3

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