Short-Term Memory HEEELLPPP!


#1

Hi everyone,
I'm currently on this exercise, and i've done my code, however there seems to be an error involving the scan function and I don't seem to find the problem.
Can anyone help?
Thanks

var cashRegister = {
    total: 0,
//insert the add method here    
    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;
        
        //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"*2,"magazine"*3);
//Show the total bill
console.log('Your bill is '+cashRegister.total);


#2

here:

cashRegister.scan=("eggs"*2,"magazine"*3);

why do you use a equal sign? this means assign, general syntax for calling method:

objectName.methodName(argument1, argument2)

also, "eggs"* 2 will result in "eggseggs", you will need to call the method multiply times


#3

Thank you.
Its the simple mistakes that makes things difficult. I also noticed the scan function wasn't working because I was missing a comma at the end of the add function code block.


#4

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