<p>This practice problem is designed to help make you comfortable with working with an object's properties - creating them, referencing them, and iterating over them. There are two parts to this practice problem.</p>
<ol>
<li>Add two keys and values to this object. You can make them anything you like: title, shoe size, height and weight...whatever. You may also change the values provided if you prefer, so that this object describes anyone you like.</li>
<li>Add code to this example that will iterate over this object's properties and write each property name and its value using the logMessage() function provided. Remember that in the lesson, we talked about the <br/><code>for (key in object){}</code> looping technique. </li>
<p><b>Output:</b>
</p>
<div id="output"></div>
// Initialize our personInfo Object
var personInfo = {
fname: "Bill",
lname: "Adama",
addr: "Galactica CIC",
email: "N/A",
birthplace: "New York",
age: "40"
}
// Utility function for logging convenience
// Logs msg to the element with given id
// If id is undefined, logs to #output
function logMessage(msg, id) {
if (!id) {
id = "output";
}
document.getElementById(id).innerHTML += msg + "<br>";
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.