I'm trying to create a dynamic bracket for the NFL playoffs with javascript. The bracket is different than a traditional tournament bracket because the match-ups in round 2 and 3 are based on the teams rank. So I created this object with all the teams and their rank -
const library = {
afc: {
teams: {
t01: {
name: 'Chiefs',
rank: 1,
},
t02: {
name: 'Bills',
rank: 2,
},
t03: {
name: 'Steelers',
rank: 3,
},
t04: {
name: 'Titans',
rank: 4,
},
t05: {
name: 'Ravens',
rank: 5,
},
t06: {
name: 'Browns',
rank: 6,
},
t07: {
name: 'Colts',
rank: 7,
},
}
}
}
On the HTML side I have the first 3 matchups like this -
<div class="matchup" id="game">
<label>7 Colts @ 2 Bills</label>
<select>
<option value="Bills" id="team-1-r1-1">Bills</option>
<option value="Colts" id="team-2-r2-2">Colts</option>
</select>
</div>
I want to create a function that pulls the value that is selected and if that value matches the name it will pull the other value (key is rank) in that object.
Then once I have the rank, I can run it through another function to determine the highest to lowest ranked teams, and I can use those to populate round 2 and 3.
I know that if I do const teamObj = Object.values(library.afc.teams) I can get an array with an object of each team, but I don't know how to iterate through the array and pull the match