3. short term memory


#1


i can't find where is my error :frowning: help me please!!


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 "choolate" :
            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

never mind _ _! i wrote "chocolate"wrong


#3

I used your code, and corrected "chocolate" and still im gettting a syntax error, help please


#4

Try " : " instead of " ; " after magazine.


#5

delgato is right :slight_smile:
and this is my update code :

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


#6

I get the following error: "Oops there was a problem with your syntax"
I put my code into CodeacademyLabs and it indicates at my scan: function(item) { line that I am missing }
I am sorry, but I have looked over my code, reset it and retyped it (twice) and I still cannot see where my syntax issue is. Help!

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");
cashRegister.scan("eggs");
cashRegister.scan("magazine");
cashRegister.scan("magazine");
cashRegister.scan("magazine");

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


#7

in the Hint , it said : Comma don't forget that a comma (,) will be needed after closing the new add method!
you should put a comma at the end of the add function . try this again if it works.

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


#8

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