3/7 help


#1
var cashRegister = {
    total: 0,  
    add: function (itemCost){
      this.total + itemCost = total; },  
   
    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
scan("eggs");
scan("eggs"):
scan("magazine");
scan("magazine");
scan("magazine");

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

#2

-1
you might want to change your
this.total + itemCost = total;
into
this.total = itemCost + this.total;

-2
If you want to call the scan Method of the cashRegister object
you will have to mention the cashRegister object
so that the Javascript interpreter knows where to find this scan Method
like
**cashRegister.scan("eggs");

= = = = = = = = = = = = = = = = =

nice to know

You could test in labs.codecademy.com
choose Javascript
You will get a split-screen
In the left-hand-side you paste-in your code
click on the Run button.
The right-hand-side is the console

references

www.crockford.com --> for most respected guide-line in Javascript
like coding convention
www.crockford.com
http://javascript.crockford.com/code.html
http://javascript.crockford.com/survey.html


#3

general search

Did you try...
http://www.codecademy.com/guidance/choose

Reference

google search
== the Book ==
javascript [your question] site:developer.mozilla.org

== discussions / opinions ==
javascript [your question] site:stackoverflow.com

== guidance ==
www.crockford.com
http://javascript.crockford.com/code.html
http://javascript.crockford.com/survey.html


https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript
www.developer.mozilla.org/en-US/docs/Web/JavaScript/Guide


#4

If we look at the first lesson, a completed example is there for us to compare to.

this.total += itemCost || 0;