This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by NiekTalloen
over 8 years

(4:7) Adding quantity to cashRegister.scan

Dear people reading,

I have been looking at my code for about 30 min and I can’t seem to figure out what’s wrong with it.

var cashRegister = { total:0, add: function(itemCost){ this.total += itemCost; }, scan: function(item, quantity) { switch (item, quantity) { 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(“eggs”, 4); cashRegister.scan(“milk”, 4); cashRegister.scan(“magazine”, 4); cashRegister.scan(“chocolate”, 4); //Show the total bill console.log(‘Your bill is ‘+cashRegister.total);

whenever i lat this run is logs “Your bill is 0” and it gives an error saying “Oops, try again. It doesn’t seem like your ‘quantity’ actually works!” I’m realy confused since I don’t seem to be able to find what’s wrong with it. I even looked at Hint! and to me it seems like everything I did was right.

Any help is appreciated!

Answer 55ba2a86d3292f51b100052e

0 votes

Permalink

This worked for me.

var cashRegister = { total:0, add: function(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; } } };

// scan each item 4 times cashRegister.scan(“eggs”, 4); cashRegister.scan(“milk”, 4); cashRegister.scan(“magazine”, 4); cashRegister.scan(“chocolate”, 4);

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

points
Submitted by Adriana Nunez
over 8 years

1 comments

NiekTalloen over 8 years

thank you i now see what’s wrong, the my switch could not have 2 parameters =)

Answer 55ba477b9376769f600001a2

0 votes

Permalink

The mistake is switch(item,quantity). i.e switch(item )

points
Submitted by DV Babu
over 8 years