I'm new to objects in javascript and I'm having some problems with the following 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
}
}
}
What I want to do is get the colorHex value like this but it isn't working:
var newColor = new Color("White");
alert(newColor.getCode().colorHex);
What am I doing wrong?