58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
const weekdays = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
|
|
|
|
const openingHours = {
|
|
[weekdays[3]]: {
|
|
open: 12,
|
|
close: 22,
|
|
},
|
|
[weekdays[4]]: {
|
|
open: 11,
|
|
close: 23,
|
|
},
|
|
[weekdays[5]]: {
|
|
open: 0, // Open 24 hours
|
|
close: 24,
|
|
},
|
|
};
|
|
|
|
const restaurant = {
|
|
name: "Classico Italiano",
|
|
location: "Via Angelo Tavanti 23, Firenze, Italy",
|
|
categories: ["Italian", "Pizzeria", "Vegetarian", "Organic"],
|
|
starterMenu: ["Focaccia", "Bruschetta", "Garlic Bread", "Caprese Salad"],
|
|
mainMenu: ["Pizza", "Pasta", "Risotto"],
|
|
order: function (starterIndex, mainIndex) {
|
|
return [this.starterMenu[starterIndex], this.mainMenu[mainIndex]];
|
|
},
|
|
// man kann ein Objekt außerhalb eines anderen Objectes definieren, und es nachträglich bei einem anderen Objekt verwenden
|
|
openingHours,
|
|
orderDelivery: function ({
|
|
starterIndex = 1,
|
|
mainIndex = 0,
|
|
time = "20:00",
|
|
address,
|
|
}) {
|
|
console.log(
|
|
`Order recieved! ${this.starterMenu[starterIndex]} and ${this.mainMenu[mainIndex]} will be delivered to ${address} at ${time}`
|
|
);
|
|
},
|
|
};
|
|
|
|
for (const day of Object.keys(restaurant)) {
|
|
console.log(day);
|
|
}
|
|
// die Ausgabe der Eigenschaften eines Objektes nach dem Schllüsel(key)
|
|
const keyProperties = Object.keys(openingHours);
|
|
console.log(keyProperties);
|
|
// die Ausgabe der Eigenschaften eines Objektes nach dem Wert(value)
|
|
const valueProperties = Object.values(openingHours);
|
|
console.log(valueProperties);
|
|
|
|
// die Ausgabe des Eigenschaften eines Objektes nach dem Objekt(key,value)
|
|
const objectProperties = Object.entries(openingHours);
|
|
console.log(objectProperties);
|
|
|
|
for (const [day, { open, close }] of objectProperties) {
|
|
console.log(`On ${day} we open at ${open} and close at ${close}`);
|
|
}
|