- For-Of Loop
- Enhanced Object Literals
- Optional Chaining (?.)
- Looping Object : Object Key, Value and Entries
const game = {
team1: 'Bayern Munich',
team2: 'Borrussia Dortmund',
players: [
[
'Never',
'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,
},
};
//Challenge2
//entries = index
//1.
for (var [i, player] of game.scored.entries()){
console.log('Goal'+(i+1)+':'+player);
}
//2.
let average = 0;
const odds = Object.values(game.odds);
for (const odd of odds) average += odd;
average /= odds.length;
console.log(average);
//3.
for (const [team, odd] of Object.entries(game.odds)){
console.log(team, odd);
}