I have a project that will involve nested switch statements. I am trying to learn JavaScript object literals to use in the project.
I used the examples in the Mozilla Developers Network and set up a simple test page. I eventually want to use more complex object literals. But, the alert windows in my first simple test are showing "undefined".
<script type="text/javascript">
function displayFile(whatOption, whatColor)
{
var Test01 =
{
rectangle: "DefaultFile",
square: "SquareFile"
};
var filename = (Test01.whatOption);
alert (filename);
var Test02 =
{
red: "RedFile",
blue: "BlueFile"
};
var filename2 = (Test02.whatColor);
alert(filename2);
}
</script>
</head>
<body >
<p onclick="displayFile('rectangle', 'red')">[ Red ]</p>
<br/>
<p onclick="displayFile('square', 'blue')">[ Blue ]</p>
<br/>
<p onclick="displayFile('square', 'gray')">[ Gray ]</p>