hinzugefügt challenge über rest und spread Operator, enhanced Object Literal, Optional Chaining
This commit is contained in:
parent
d830e52103
commit
7c6e91e284
114
javascript/Javascript Expert/chapter09/challenge1.js
Normal file
114
javascript/Javascript Expert/chapter09/challenge1.js
Normal file
@ -0,0 +1,114 @@
|
||||
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);
|
||||
@ -9,7 +9,7 @@ const david = {
|
||||
const { firstName, lastName, age } = david;
|
||||
console.log(firstName, lastName, age);
|
||||
|
||||
const restauraunt = {
|
||||
const restaurant = {
|
||||
name: "Classico Italiano",
|
||||
location: "Via Angelo Tavanti 23, Firenze, Italy",
|
||||
categories: ["Italian", "Pizzeria", "Vegetarian", "Organic"],
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Destructuring Objects</title>
|
||||
<script src="shortCircuitOperators.js"></script>
|
||||
<script src="challenge1.js"></script>
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user