Why wont this work


#1


    scan: function(item,num) {
        for(i=0;i<=num;i++)
        {
        switch (item) {
        case "eggs": this.add(0.98); break;
        case "milk": this.add(1.23); break;
        case "magazine": this.add(4.99); break;
        case "chocolate": this.add(0.45); break;
        }
        
        }   
    }
};


#2

here:

for(i=0;i<=num;i++)

you use <= in the loop condition, this means the item will be scanned one more time then it should:

cashRegister.scan('eggs',4);

would be scanned 5 times

The loop doesn't seem to work at all, even though its correct, check the hint


#3

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