Building a cash Register.!


#1

My code below obviously works, but this ‘not so smart’ engine of yours doesn’t recognize it and for that reason I cannot move on… already tried in Chrome and Opera and I will not install another browser to solve this.

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

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


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

THE OUTPUT OF THIS CODE, AS COPIED FROM THE CONSOLE:

Your bill is 30.6


#2

please share exercise url, this seems to be the old course which is no longer supported


#3

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

here is the URL.

But I don’t really understand, if it is not supported anymore, why is it still active? it is true that I followed an older link from a document, but since it was working, I assumed it should be fine. Now that I think about it, it is old since it doesn;t support ‘let’ or ‘const’ declarations.


#4

i don’t know, personally, i think it should just be taken down

i do recommend updating the latest supported courses which can be found on the main site

The exercise doesn’t approve of using a loop, you need to simply multiply the price (for example .45 for chocolate) with quantity when calling add, its also more efficient then your while loop


#5

well that solves the problem then and I do agree that this solution is more efficient. that was the one that came to mind at that point. I will try and follow the more recent courses.

Thanks for your time and effort!


#6