The game in this example has a variable number of players. A score needs to be tracked for each player. The example managed to create the HTML needed, but I'm not sure how to reference each child. Here's the HTML:
var players=prompt("Number of players?",2);
oldNode = document.getElementById("scoreHolder");
for (x=1;x<players;x++) {
newNode = oldNode.cloneNode(true);
document.documentElement.appendChild(newNode);
}
var c=document.getElementById("scoreHolder").childNodes;
c[1].style.backgroundColor = "yellow";
c[2].style.backgroundColor = "blue";
<div id="scoreHolder">Player 1 score: <span id="score">0<span></div>
This example turns part of the first line of HTML yellow, but does nothing with the other lines. How can I reference them so that I can update each player's score?