Javascript problem

0

I want to build a table in javascript using two arrays one for the months and another for the days of each month. I want to show a row with the months and below a row with the days. Start as follows:

<script type="text/javascript">
		var meses =["enero","febrero","marzo","abril","mayo","junio","julio","agosto","septiembre","octubre","noviembre","diciembre"];
		var dias = [31,28,31,30,31,30,31,31,30,31,30,31];

		var result = "";

		for (var i = 0; i < meses.length; i++) {
			document.write(meses[i]+" ");
			for (var j = 0; j < dias.length; j++) {
				document.write(dias[j]);
			}
		}

		//document.getElementById("meses").innerHTML = "<td>"+meses[i]+"</td>";
		//document.getElementById("dias").innerHTML = "<td>"+dias[j]+"</td>";

	</script>

But it does not work for me ... I do not know how to make the two arrays come together to be able to insert them in a table ...

    
asked by Cristian Navarro Fernandez 21.12.2018 в 02:23
source

1 answer

1

You still need to start the table, the rows and the columns, besides your cycles should not be nested, otherwise you would show every day for every month, knowing that your code should look like this:

var meses =["enero","febrero","marzo","abril","mayo","junio","julio","agosto","septiembre","octubre","noviembre","diciembre"];
var dias = [31,28,31,30,31,30,31,31,30,31,30,31];
var result = "";
document.write("<table><tr>")
for ( i = 0; i < 12; i++)
{
    document.write("<td>"+meses[i]+" </td>");
}
document.write("</tr><tr>")
for ( j = 0; j < 12; j++) {
    document.write("<td>"+dias[j]+" </td>");
}
document.write("</tr></table>")
    
answered by 21.12.2018 / 02:46
source