title: Get variable from object method in javascript
body: <p>I'm new to objects in javascript and I'm having some problems with the following code.</p>
  
  <pre><code>var Color = function(color){
     this.color = color;
     this.getCode = function(){
        var colorHex;
        var colorRBG;
        switch(color){
            case "White":
                colorHex = "#ffffff";
                colorRGB = "255,255,255";
                break;
            case "Black":
                colorHex = "#000000";
                colorRGB = "0,0,0";
                break;
            default:
                return false;
        }
        return {
            colorHex: colorHex,
            colorRGB: colorRGB
        }
     }
  }
  </code></pre>
  
  <p>What I want to do is get the colorHex value like this but it isn't working:</p>
  
  <pre><code>var newColor = new Color("White");
  alert(newColor.getCode().colorHex);
  </code></pre>
  
  <p>What am I doing wrong?</p>