This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
web_design:horario:arrays [2021/10/11 19:29] mag [Arrays] |
web_design:horario:arrays [2023/08/16 09:33] (current) |
||
---|---|---|---|
Line 132: | Line 132: | ||
* The third says that each time the loop finishes, we should increment p (add 1). | * The third says that each time the loop finishes, we should increment p (add 1). | ||
* The second says to keep going while < | * The second says to keep going while < | ||
+ | * Now, for each player, we need to create the statsRow as for the single player. | ||
+ | * We no longer have the variable called ospinaRamirez, | ||
+ | < | ||
+ | statsRow | ||
+ | statsRow += "< | ||
+ | statsRow += "< | ||
+ | statsRow += "< | ||
+ | statsRow += "< | ||
+ | * Place this code inside the for loop between the < | ||
+ | * Finally, we can add the row to the table. | ||
+ | < | ||
+ | newRow = tableBody.insertRow(p); | ||
+ | newRow.innerHTML = statsRow;</ | ||
+ | * Notice that we've changed the < | ||
+ | * There' | ||
+ | * Our final code looks like this. | ||
+ | < | ||
+ | [' | ||
+ | [' | ||
+ | ['Juan Guillermo', | ||
+ | [' | ||
+ | ]; | ||
+ | | ||
+ | tableBody = document.getElementsByTagName(" | ||
+ | |||
+ | // loop through all players | ||
+ | for (p = 0; p < players.length; | ||
+ | // create stats string | ||
+ | statsRow | ||
+ | statsRow += "< | ||
+ | statsRow += "< | ||
+ | statsRow += "< | ||
+ | statsRow += "< | ||
+ | | ||
+ | // add row to table | ||
+ | newRow = tableBody.insertRow(p); | ||
+ | newRow.innerHTML = statsRow; | ||
+ | }</ | ||
+ | * This looks a lot more efficient now, but you still might think that it's easier to create the table in HTML than Javascript. Ok. What about if we use the full team? Can you imagine building the table with 26 players? Creating the array is much easier. | ||
+ | |||
+ | [[web_design: |