Not sure when to use . and when to use [ ] while accessing Objects. Why am I getting an error