4. I have to scan it more than once?



I’ve found most illogical thing I saw in your(otherwise nice to refresh JS) course.

This passes OK:
cashRegister.scan(“eggs”, 4);
cashRegister.scan(“milk”, 4);
cashRegister.scan(“chocolate”, 4);

This does not:
cashRegister.scan(“milk”, 4);
cashRegister.scan(“eggs”, 4);
cashRegister.scan(“chocolate”, 4);

Come on, what the ■■■■ :slight_smile: it’s just a matter of checking if each line is present instead of checking for block of text. Please :wink:


Looks to me like you’re scanning each item once in both versions, but in different order, perhaps that matters.

Oh. that’s the title of the exercise :s

… still looking at it! brb


I’m getting a total of 20.209999999999997
and the submission test is looking for 20.21, how messed up is that?

I was using a loop to add them, which caused the result to be sliightly different, but multiplying the price by the quantity before adding them got me to pass. It passes for both of your versions.

So perhaps you’re encountering something similar.

You can add

console.log('total after scan ' + this.total);

And the value that the submission test is looking for is 20.21, so if you’re getting ALMOST that, like I did, then try changing how you compute what to add. (as mentioned, multiplying did the trick for me)

The cause of this is that they do exact comparisons between floats, that doesn’t really make sense because floats are approximations. Instead they should be doing testing if it’s “almost equal”


I wasn’t using a loop, only multiplying what I’m passing to add method. Oh well, I guess it’s related exclusiely to parser judging the test.