[Solved] Code doesn’t add rows to table (HTML / JavaScript) [duplicate]


The code seems to work but would makes strange html. Rows (tr elements) should contain cells (td elements). And your not iterating over your game_names array your just iterating from 0 to ten. See my example of your code below.

var game_names = [
  "first_game",
  "second_game",
  "third_game",
  "fourth_game",
  "fifth_game"
];

var parent = document.getElementById("games");


for (i=0;i<=game_names.length;i++){
    var childRow = document.createElement("tr");
    var childCell = document.createElement("td");
    var node = document.createTextNode("hi!");
    childRow.appendChild(childCell);
    childCell.appendChild(node);
    parent.appendChild(childRow);
}

1

solved Code doesn’t add rows to table (HTML / JavaScript) [duplicate]