4/7 please help I tried everything


#1



4/7 please help I tried everything :slight_smile:


help me here is my code..


Replace this line with your code. 
var cashRegister = {
    total:0,
    add: function(itemCost){
        this.total += itemCost;
    },
    scan: function(item, quantity) {
        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("chocolate", 1);
cashRegister.scan("magazine", 1);
cashRegister.scan("eggs", 1);
cashRegister.scan("milk", 1)

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


#2

Hi you should scan each item 4 time.

cashRegister.scan("chocolate", 4);
...........

#3

hahah thank you :wink:


#4

can you check it for me??

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

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


#5

this part

scan: function(item) {
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;
}
}

like that instruction says

Modify the scan method such that if we tell it the quantity of each item, it will be able to add the right amount to the total

first here

scan: function(item)

you should add the argument quant could be any other word you want..

scan: function(item, quant)

then in each case you should multiply the quantity by the price like that

case "milk": this.add(1.23 * quant); break;