Why?what's meaning?


#1


Is there someone tell me what;s meanning?please.

Oops, try again. Calling cashRegister.add(3.2) set the cashRegister.total to 0 instead of 3.2

var cashRegister = {
    total:0,
//insert the add method here    
    add:function(itemCost){
        this.itemCost+=itemCost;
    },
    
    scan: function (item) {
        switch (item) { 
        case "eggs": 
            this.add(0.98); 
            break;
        
        case "milk": 
            this.add(1.23); 
            break;
        
        //Add other 2 items here
        case "magazine":
            this.add(4.99);
            break;
            case "chocolate":
                this.add(0.45);
                break;
        
        }
        return true;
    }
};

//Scan 2 eggs and 3 magazines
cashRegister.scan('eggs')
cashRegister.scan('eggs')
caseRegister.scan('magazine')
//Show the total bill
caseRegister.scan('magazine')
caseRegister.scan('magazine')
console.log('Your bill is '+cashRegister.total);


#2

Did you mean to write,

this.total += itemCost;

?


#3

yes,then ?what should I do ?


#4

Not sure I follow your question. Could you please post a link to this exercise so we're on the same page and can see what is expected. Thanks.


#5

https://www.codecademy.com/courses/close-the-super-makert/0/3

Please.


#6

With that correction, is your code still not running as expected? You should see the following in the console:

Your bill is 16.93

#7

yes ,Is your code running correctly?


#8

what my output is :Your bill is 0


#9

Mine is, but I haven't tested yours.

Here is a spoiler that you may compare yours to:


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;
        }
        return true;
    }
};
cashRegister.scan("eggs");
cashRegister.scan("eggs");
cashRegister.scan("magazine");
cashRegister.scan("magazine");
cashRegister.scan("magazine");
console.log('Your bill is '+cashRegister.total);

#10

Cool ,I got it ,thank you .


#11

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