A little enlightenment here please


I can pass this exercise , However. i need to know first why this isn't working , though it printed the exact result of the sum of all items multiplied by the "quantity" parameter ..
I just need to understand .

scan: function(quantity,item) {
    switch (item) {
    case "eggs": this.add(quantity*0.98); 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;




What error message are you getting? Might it be that the SCT is looking for particular code patterns?

 function(item, quantity)
this.add(0.98 * quantity)



I just had to move the quantity parameter after the item parameter ..
seems very silly but .... oh well ..


it said , "it doesn't seem that your quantity method works " , and printed the accurate result but with a lot of decimals ,
so next I tried the "Math.floor" to decrease the digits , but that didn't work either
At last i just replaced the "quantity" parameter after the "item" and it worked


The lesson checker could be looking at any number of elements of our code, including as seen above, the parameter list for the function. In a later lesson it actually insists upon the correct order (when order shouldn't matter),

The large decimal values are typical of computations done by a computer. It is known as floating point arithmetic error, though error is so infinitismally small as to not be of concern.

Math.floor is not the method to reach for. toFixed() is. But... don't use it unless asked. If we use all the values given, and the expected order, the final result does not need to be fixed.


Thank you for such useful info :slight_smile: :slight_smile:


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