This forum is now read-only. Please use our new forums! Go to forums
Please help me in this : Did you scan four of each item?
Here is a code: Where is my mistake?
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',1);
cashRegister.scan('milk',1);
cashRegister.scan('magazine',1);
cashRegister.scan('chocolate',4);
//Show the total bill
console.log('Your bill is '+cashRegister.total);
Answer 52763367f10c606f04002ed2
0 votes
That’s my question too. Did you scan each item four times? Examine line 16 to line 18 and see what needs to be changed.
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
10 comments
I’ve tried everything but the error is the same!! I don’t know …. !
I will read our line 16 to line 18 for you and see if that helps. “Scan an egg into the cash register. Scan a milk into the cash register. Scan a magazine into the cash register.” The instructions want you to scan four of each. The second argument in the function call denotes the quantity of an item to scan.
Yes the instructions want to scan four of each, this is Okay, but again is the same error. in the instructions , respectively in “hint” writes: “”Unit Test Our test expects the second parameter to be quantity as the examples above.””.This means that the second parameter should be as the examples above? I’m not understanding this because no examples to set “quantity”; Thankkss a lot!
Did you have completed this?
Yes, I have completed this. Let’s talk about something else before I decide on the best track to explain this. What do you think the scan method in the cashregister object does? Don’t just say ‘it scans an item’. Explain HOW it works.
the scan method is a method which takes two parameters (item and quantity), in our case when we have .ex. eggs or milk or something else…example in case “eggs”: this.add(0.98 * quantity), call add method which gives itemCost and quantity the return total = total + itemcost. I do not know if I’ve been clear!!!
I solved that :D
Thanks.
Well, you tried! :D Here’s a better explanation: the scan method accepts two values: an item name, and the number of that item to scan (the ‘quantity’). It then adds the cost of that item to the total as many times as the number of that item to scan by adding the product of the item’s cost and quantity to the total. The exercise wants you to scan FOUR eggs, while the current code scans ONE egg. This is because on line 16, you are saying “scan an egg 1 time” when you should be saying “scan an egg, 4 times”. That would mean that you would change the second value passed into the function from 1 to 4. Got it?
Lol, you ninja’d me by 3 minutes. Cheers! ^___^
Yes i solved this problem , thanks.