You mixed up curly braces in your js + in your html, you have to call phone.demo()
In jsfiddle, if you want to access phone from the html, don’t put var
before (it makes it private to a specific js closure and not accessible to the global space)
html
<button onclick="phone.demo();">JS Object Literals</button>
js
phone= {
name : "iPhone",
brand : "Apple",
version : "5",
edition : function(){
alert("The cellphone's Version is iPhone" + this.version);
},
demo: function(){
console.log(phone.brand);
console.log(phone.version);
console.log(phone.name);
}
}
solved Javascript : Creating Objects using Literals [closed]