This forum is now read-only. Please use our new forums! Go to forums
(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
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);
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
1 comments
thank you i now see what’s wrong, the my switch could not have 2 parameters =)