Table of Contents
show
Example 9:
Create an object called store with the properties,
- ‘name’ (string)
- ‘location’ (String)
- ‘isOpen’ (Boolean)
- ‘departments’ ( array)
The values for the properties are: “MegaMart”, “123 Main Street, Chennai”, true and array of Groceries, Electronics, Clothing respectively.
Create and object method called getStoreInfo which returns “MegaMart is located at 123 Main Street, City. It is currently open.
- Create an object called ‘manager’ with the properties
- ‘name’
- ‘age’
- ‘contact’
- The values of the properties are: John, 35, and john.megamart.com
- Add this object as property to store
- Print the name of the strore
- Print whether the store is open or not
- Print the departments in the store
- Print the name of the manager
Code
const store = {
name: "MegaMart",
location: "123 Main Street, Chennai",
isOpen: true,
department: ["Groceries", "Electronics", "Clothing"],
getStoreInfo: function () {
return `${this.name} is located at ${this.location} and it is currently ${
this.isOpen ? "open" : "closed"
}`;
},
};
/*
i) Create an object called ‘manager’ with the properties
‘name’
‘age’
‘contact’
The values of the properties are: John, 35, and john.megamart.com
Add this object as property to store
*/
const manager = {
name: "John",
age: 24,
contact: "john.megamart.com",
};
store.manager = manager;
// ii) Print the name of the store
console.log(`Name of the store is: ${store.name}`);
// iii) Print whether the store is open or not
console.log(store.getStoreInfo());
// iv) Print the departments in the store
console.log(`Departments:${store.department}`);
// v) Print the name of the manager
console.log(`Name of the manager: ${store.manager.name}`);
Output:
Views: 113