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


Hello, in the, "I have to scan it more than once?" exercise I noticed a bug that will allow you to skip the exercise without inputting any valid code. If you add letters or numbers to the default method's parameters and press save & submit it will count as being correct even though the output says your bill is 0 and there being no code added to complete the task.


Can you elaborate further?


So if I were to start this assignment and make one change either here:

scan: function(item) to scan: function(item1) or scan: function(itemex) etc.

or here:

add: function(itemCost) to add: function(itemCost1) etc.

the module would still give you a pass without actually implementing any valid changes to the code.

Perhaps a photo would be better. So here I added a 1 to the parameter named itemCost and it immediately accepted the module as complete without adding the requested code.


Agreed .... there's something off about this exercise. I typed a code that I know shouldn't work and got passed with the same line in preview.

I guess I'll just skip this exercise despite of getting pass on my code that I think to the best of my knowledge should be okay but getting undefined in preview. Don't know how much I can rely on feedback from this exercise. You can have a look at my code if you're curious ...


Yeah, it just seems that this exercise is bugged, but I do not think it is a priority for them.

As for your code, you are using an undefined variable quantity in your add function. Much like the total that you defined in the object you would need to define a quantity as well. Although for this exercise storing the quantity isn't necessary as we do not need to return it. If you did want to store the quantity you would want to do this:

var cashRegister = {
add: function(itemCost,quantity){
this.total += itemCost;
this.quantity = quantity;

scan : function ...

otherwise taking it out of that function should solve your issue.

I guess it would also be sufficient to note that you could also make quantity a local variable of that method by adding var in place of this. in front of the variable name. In your case though, you are trying to pass a parameter value that does not exist to that variable so I added it into the function in my example above. Also when you call the function you should replace the parameters with actually data whether it is another variable, string or, integer, etc so for your lines here they should be something like this:

cashRegister.scan("milk", 4);
cashRegister.scan("chocolate", 4);
cashRegister.scan("magazine", 4);
cashRegister.scan("eggs", 4);

in order for the method to parse that data correctly it takes a string parameter for the switch statement and then uses the add method for which the string parameter matches. This add function's price parameter is then multiplied by your quantity parameter to get the price of the item. Let me know if you have any other questions.

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

Hi guys! I was looking through the topic and I think I have a solution. This code actually worked for me just fine. Here's the code.

var cashRegister = {
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("chocolate", 4);
cashRegister.scan("magazine", 4);
cashRegister.scan("milk", 4);
cashRegister.scan("eggs", 4);

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


I appreciate your solution post, however, the original topic was about an inherent bug inside in this module. We weren't really looking for a solution to the module, but rather to acknowledge the bug.


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