Merge pull request #6181 from raisedadead/fix/waypoint-accessing-objects-properties-with-variables

Add an addtional example code and fix the console output
This commit is contained in:
Rex Schrader
2016-01-17 13:00:07 -08:00

View File

@ -3223,6 +3223,8 @@
"Another use of bracket notation on objects is to use a variable to access a property. This can be very useful for iterating through lists of the object properties or for doing the lookup.",
"Here is an example of using a variable to access a property:",
"<blockquote>var someProp = \"propName\";<br>var myObj = {<br> propName: \"Some Value\"<br >}<br>myObj[someProp]; // \"Some Value\"</blockquote>",
"Here is one more:",
"<blockquote>var myDog = \"Hunter\";<br>var dogs = {<br> Fido: \"Mutt\",\n Hunter: \"Doberman\",\n Snoopie: \"Beagle\"<br >}<br>var breed = dogs[myDog]; // \"Hunter\"<br>console.log(breed)// \"Doberman\"</blockquote>",
"Note that we do <em>not</em> use quotes around the variable name when using it to access the property because we are using the <em>value</em> of the variable, not the <em>name</em>",
"<h4>Instructions</h4>",
"Use the <code>playerNumber</code> variable to lookup player <code>16</code> in <code>testObj</code> using bracket notation."
@ -3242,7 +3244,7 @@
"var player = testObj; // Change this Line"
],
"tail": [
""
"if(typeof player !== \"undefined\"){(function(v){return v;})(player);}"
],
"solutions": [
"var testObj = {\n 12: \"Namath\",\n 16: \"Montana\",\n 19: \"Unitas\"\n};\nvar playerNumber = 16;\nvar player = testObj[playerNumber];"