4- Codes works, test thinks otherwise


#1


https://www.codecademy.com/courses/close-the-super-makert/0/4?curriculum_id=506324b3a7dffd00020bf661


"Oops, try again. It doesn't seem like your 'quantity' actually works!"

Well, the code returns the desired results. I'm not sure how it wants me to do this.
I guess a for loop isn't cool for adding things a set number of times?
I wondered if it wants me to add a product of quantity and cost to total instead (which seems counter-intuitive for a register, instead of just adding.)

anyway, here is the code. It logs the correct sum to the console, and works over on repl.it as well


var cashRegister = {
    total:0,
    add: function(itemCost){
        this.total += itemCost;
    },
    scan: function(item,Qty) {
        for(i=0;i<Qty;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;
        }
        }
    }
};

// scan each item 4 times
cashRegister.scan('eggs',4)
cashRegister.scan('magazine',4)
cashRegister.scan('chocolate',4)
cashRegister.scan('milk',4)

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


#2

Sometimes you have to follow the instructions perfectly. You've abbreviated 'quantity' so the despite your syntax being correct, you've not followed the instructions.


#3

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