JSFiddle - React, Tailwind, and code Playground
by Angeli Schwartz
HTML
<div id="output"></div>
JavaScript
var myAddrBookEntry = {
"fname": "Larry",
"lname": "Bouthillier",
"addr": "Rhode Island",
"email": "[email protected]",
"person-role" : "instructor",
"getFullName" : function(){
return this.fname + " " + this.lname;
},
"printMe" : function(){
return "This person is "+this.fname+" " + this.lname + " and lives in "+this.addr+" and can be reached at "+this.email;
}
}
var myCompanyEntry = {
"name" : "Google",
"location" : "Mountain View, CA",
"isPublic" : true,
"symbol" : "GOOG",
"products" : ["Android", "Chrome", "Google Search", "Google Earth"],
"printMe" : function(){
var out = "The company is "+this.name+" in "+this.location+", "
if (this.isPublic) {
out+= 'Our stock symbol is '+this.symbol+". "
}
if (this.products) {
out+= "We are known for: <ul>";
for (var i=0;i<this.products.length;i++){
out += "<li>"+this.products[i]+"</li> ";
}
out+="</ul>";
}
return out;
}
}
function printObject(obj){
if(obj.printMe){
var el = document.getElementById("output");
el.innerHTML += obj.printMe()+"<br>";
}
}
printObject(myAddrBookEntry);
printObject(myCompanyEntry);