3/7 Short-Term Memory, what is the problem here?


#1

It keeps writing me the error message: "ReferenceError: eggs is not defined",
but I just can't understand why!
Here's my 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);


#2

@bitsolver06000,

Your scan Method was defined as having 1 parameter item

As you call the cashRegister.scan() Method
and the scan Method was defined as having 1 parameter
you will have to provide 1 argument
in this case a string Value "eggs"
( and not as you are doing =eggs=, which would be a =variable= )

some quotes from the outer-world:

**argument is the value/variable/reference being passed in,
parameter is the receiving variable used within the function/block**

OR

**"parameters" are called "formal parameters",
while "arguments" are called "actual parameters".**


#3

//Scan 2 eggs and 3 magazines
cashRegister.scan("eggs");
cashRegister.scan("eggs");
cashRegister.scan("magazine");
cashRegister.scan("magazine");
cashRegister.scan("magazine");


#4

@adam_spice,

Please present the full code which you are using...

The call's seem to be correct.


#5

//Here is a exact 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
i=prompt("enter how many items u would like to buy")
for(k=1;k<=i;k++){
j=prompt("which item u would like to buy")
l=prompt("enter how many " +j+" you would like to buy")
for(m=1;m<=l;m++){
cashRegister.scan(j)
}
}

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


#7

Semi-colon is missing:

Marry Xmas
Sir Random Name