115 lines
2.8 KiB
JavaScript
115 lines
2.8 KiB
JavaScript
const game = {
|
|
team1: "Bayern Munich",
|
|
team2: "Borrussia Dortmund",
|
|
players: [
|
|
[
|
|
"Neuer",
|
|
"Pavard",
|
|
"Martinez",
|
|
"Alaba",
|
|
"Davies",
|
|
"Kimmich",
|
|
"Goretzka",
|
|
"Coman",
|
|
"Muller",
|
|
"Gnarby",
|
|
"Lewandowski",
|
|
],
|
|
[
|
|
"Burki",
|
|
"Schulz",
|
|
"Hummels",
|
|
"Akanji",
|
|
"Hakimi",
|
|
"Weigl",
|
|
"Witsel",
|
|
"Hazard",
|
|
"Brandt",
|
|
"Sancho",
|
|
"Gotze",
|
|
],
|
|
],
|
|
score: "4:0",
|
|
scored: ["Lewandowski", "Gnarby", "Lewandowski", "Hummels"],
|
|
date: "Nov 9th, 2037",
|
|
odds: {
|
|
team1: 1.33,
|
|
x: 3.25,
|
|
team2: 6.5,
|
|
},
|
|
};
|
|
|
|
const [player1, player2] = game.players;
|
|
const [gk, ...fieldPlayers] = player1;
|
|
const allPlayers = [...player1, ...player2];
|
|
const playersFinal = [...player1, "Thiago", "Countinho", "Periscic"];
|
|
const {
|
|
odds: { team1, x: draw, team2 },
|
|
} = game;
|
|
const printGoals = function (...players) {
|
|
console.log(`${players.length} goals we are scored`);
|
|
};
|
|
|
|
team1 < team2 && console.log("Team 1 is more likely to win");
|
|
team1 > team2 && console.log("Team 2 is more likely to win");
|
|
|
|
printGoals(...game.scored);
|
|
const weekdays = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
|
|
|
|
// sehe den Kommentar unten
|
|
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}`
|
|
);
|
|
},
|
|
};
|
|
|
|
console.log(openingHours);
|
|
|
|
// console.log(restaurant.openingHours.sum?.open);
|
|
|
|
const menu = [...restaurant.starterMenu, ...restaurant.mainMenu];
|
|
for (const item of menu) {
|
|
console.log(item);
|
|
}
|
|
|
|
for (const [index, item] of menu.entries()) {
|
|
// console.log(item);
|
|
// console.log(`${item[0]} : ${item[1]}`);
|
|
// console.log(...item);
|
|
console.log(`${index} : ${item}`);
|
|
}
|
|
// optional chaning Operator, gibt kein Fehler aus, wenn eine Eigenschaft/Variable/Wert eines Objektes nicht existiert
|
|
console.log(restaurant.openingHours.mon?.open);
|