3. Short Term Memory


#1

When I go to run my code I am getting "Oops, try again. Have you scanned eggs twice and magazine three times?" error and my output shows it is going through all the scan item cases. Any thoughts on why it won't go through?

var cashRegister = {
total: 0,
//insert the add method here
add: function(itemCost){
this.total += itemCost;
},

scan: function (item) {
    console.log(item);
    switch (item) { 
    case "eggs": 
        this.add(0.98); 
    break;
    case "milk": 
        this.add(1.23); 
    break;
    case "chocolate" :
        this.add(4.99);
    break;
    case "magazine":
        this.add(0.45);
    break;
    }
    return true;
}

};

//Scan 2 eggs and 3 magazines
cashRegister.scan("eggs");
cashRegister.scan("eggs");
cashRegister.scan("magazine");
cashRegister.scan("magazine");
cashRegister.scan("magazine");

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


#2

That's quite an expensive chocolate you have there! I think I'll take the magazines instead... ;)


#3

remove the console.log (item) from here, you don't need it.


#4

@microsurfer22225 @wavara Thank You!


#5

I have same error too, How did you fix your code?


#6

^ is the answer, the prices of chocolate and magazine where swapped. beautiful answered by wavara

If that doesn't solve the problem, make a new topic with your code + error message, for all we know your problem might be different (there are so many things which can go wrong)


#7