3/7 syntax error can not find a problem


#1


syntax error

var cashRegister = {
    total: 0,
//insert the add method here    
    add: function(itemCost) {
        total += itemCst
        };
    
    
    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
cashRegiser.scan("eggs");
cashRegiser.scan("eggs");
cashRegiser.scan("magazine");
cashRegiser.scan("magazine");
cashRegiser.scan("magazine");

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


#2

Hi this part

 add: function(itemCost) {
        total += itemCst
        };

you wrote itemCst instead of itemCost


#3

@ericentrepreneur,

+++++ identifier error cashRegister object.

If you define a function in a literal-notatet object
you do not end this function-statement with a semi-colon...REMOVE the semi-colons-;

An object has one or more properties which are separated by a comma-,
Each property consists of a property-key and it's associated VALUE

Your cashRegister object has 3 properties.
a total property with property-key total and it's associated number VALUE 0
an add property with property-key add and it's associated function VALUE
an scan property with property-key scan and it's associated function VALUE

You have to separate these properties with a comma-,
You used the ,-separator between the total property and the add property.
You forgot the one between the add property and the scan property.

P.S.
When you are defining a function within an object
you call this property a Method.
So you have defined an add Method
and a scan Method in cashRegister object.


#4

I fixed Cost but still not working


#5

read the post of @leonhard.wettengmx.n about the semi-colon. and the erro come from here

add: function(itemCost) {
        total += itemCost
 };

#6

//// I fixed but it's not working

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


#7

//I added comma and erased semicolon as you said.
it's not working

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


#8

@ericentrepreneur

Have close look at your

itemCst


#9

@ericentrepreneur,

Have close look at

cashRegiser


#10

I have already fixed

message is total is not defined...
sorry leonhard.......please help

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


#11

@ericentrepreneur,
To refer to the total property
you will have to use

this.total

#12
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("magazine");
cashRegister.scan("magazine");
cashRegister.scan("magazine");
cashRegister.scan("eggs");
cashRegister.scan("eggs");
//Show the total bill
console.log('Your bill is '+cashRegister.total);