# I have to scan in more than once. Quantity isn't defined ? Otherwise works?

#1

Getting "way to go" but preview shows "quantity undefined" .....

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

this.total += itemCost;
this.quantity = quantity;

},
scan: function(item, quantity) {
switch (item) {
}
}
};

// scan each item 4 times
cashRegister.scan("eggs" * quantity);
cashRegister.scan("milk" * quantity);
cashRegister.scan("magazine" * quantity);
cashRegister.scan("chocolate" * quantity);

//Show the total bill

#2

HI these lines

``````cashRegister.scan("eggs" * quantity);
cashRegister.scan("milk" * quantity);
....``````

you should call it like that

``cashRegister.scan(item, quantity);``

they shuld be separate by a comma and where you put quantity (you should put teh quanitty they aske you to scan)

#3

Okay this is my updated code:

var cashRegister = {
total:0,

``````add: function(itemCost){
this.total += itemCost;
this.quantity = quantity;

},
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;
}
}``````

};

// scan each item 4 times
cashRegister.scan(item, quantity);
cashRegister.scan(item, quantity);
cashRegister.scan(item, quantity);
cashRegister.scan(item, quantity);

//Show the total bill

but still getting error saying quantity isn't defined.

I have to scan it more than once? (BUG)
#4

Also these 4 lines:

cashRegister.scan(item, quantity);

I don't think it's correct since I'm clearly asked to scan EACH ITEM four times. Meaning item needs to be specified in parentheses and how many of them should be specified too. These four lines represents me having the hand-scanner scanning each product and just type how many you checking out. I might be wrong though ...

#5

In case someone else has trouble with this as well:

#6

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