hinzugefügt einer Aufgabe bezüglich der Ausgabe der Eingaben des game.odds Objektes, Berechnung des Durschnitts der Wetten
This commit is contained in:
parent
5d451af3b2
commit
cc8c908862
58
javascript/Javascript Expert/chapter09/challenge2.js
Normal file
58
javascript/Javascript Expert/chapter09/challenge2.js
Normal file
@ -0,0 +1,58 @@
|
||||
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,
|
||||
},
|
||||
};
|
||||
|
||||
for (const [index, player] of game.scored.entries()) {
|
||||
console.log(`Goal ${index + 1}: ${player}`);
|
||||
}
|
||||
let avgScore = 0
|
||||
let odds = Object.values(game.odds);
|
||||
|
||||
for (const odd of odds) {
|
||||
avgScore += odd;
|
||||
}
|
||||
avgScore /= odds.length
|
||||
console.log(avgScore);
|
||||
|
||||
const objOdds = Object.entries(game.odds);
|
||||
for (const [team, quota] of objOdds) {
|
||||
const nameStr = team === "x" ? "draw" : `victory ${game[team]}`
|
||||
console.log(`Odd of ${nameStr}: ${quota}`);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user