0

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>
Junco
  • 281
  • 1
  • 4
  • 12
  • change it to : `Test01[whatOption]` – juvian Oct 03 '14 at 19:34
  • Thank you very much. The bracket notation shown here and in the other question's solution worked. I did search for an answer before posting my question. I guess I just wasn't using the right words to find it. – Junco Oct 03 '14 at 20:29

0 Answers0