I have a problem generating the hours in a JavaScript table, I use a for to add the hours in pairs but I do not add anything, the same number is repeated again and again, and another problem would be like writing the days of the week in the top row of the table.
This is how I want to develop the table, but I do not know if I am developing the table well to be able to do this.
function genera_tabla() {
var body = document.getElementsByTagName("body")[0];
var tabla = document.createElement("table");
var tblBody = document.createElement("tbody");
for (var i = 0; i < 4; i++) {
var hilera = document.createElement("tr");
var a;
// Imprime las horas.
for (a = 0; a < 8; a = a+2){
hilera.textContent = a;
}
for (var j = 0; j < 4; j++) {
let elmt = (j == 0 || i == 0) ? "th" : "td";
var celda = document.createElement(elmt);
var textoCelda = "fila " + i + ", columna " + j + "\n";
celda.textContent = textoCelda;
hilera.appendChild(celda);
}
tblBody.appendChild(hilera);
}
tabla.appendChild(tblBody);
body.appendChild(tabla);
tabla.setAttribute("border", "2");
}
<html>
<input type="button" value="Genera una tabla" onclick="genera_tabla()">
</html>