Reputation:
So I'm making a game, but I'm having trouble selling items. I made the object
var price = {
sword:3,
fish:1
}
And once you click on something with class "item", it should tell you the price Except It isn't working
$(".item").click(function(){
alert(price.(this.id))
});
Can someone help me?
Upvotes: 0
Views: 104
Reputation: 56
Replace
alert(price.(this.id))
To
alert(price[this.id])
You can't access object properties by dynamic names from dot notation, use subscript notation.
Upvotes: 3