2
I want the user to enter the row and column quantity of a table and present the respective values entered in the table. But typing the number of rows and columns at the prompt does not display the table and values.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Untitled Document</title>
<style>
.verde{
background-color: green;
}
.amarelo{
background-color: yellow;
}
</style>
<script>
function criaTabela(linha,coluna){
conteudo="";
conteudo += "<table border='1'>";
for (i=1;i<=linha;i++){
conteudo += "<tr>";
for (j=1; j<=coluna;j++){
if(j % 2 == 0) {
conteudo += "<div class='coluna_verde'><td>"+ i +" " + j +"</td></div>";
}
else{
conteudo += "<div class='coluna_amarelo'><td>"+ i +" " + j +"</td></div>";
}
}
conteudo += "</tr>";
}
conteudo += "</table>";
document.getElementById("tab").innerHTML=conteudo;
}
window.onload=function(){
do{
var linha= prompt("Digite a quantidade de linha");
var coluna= prompt("Digite a quantidade de coluna");
criaTabela(linha,coluna);
}while (linha != null && coluna !=null );
console.log("linha"+linha);
console.log("coluna"+coluna);
}
</script>
</head>
<body>
<div id="tab"></div>
</body>
</html>
The person has to type the number of rows and columns, and the script has to draw the table? (as lines and columns typed) ???
– Milrak Pereira Pessoa
Do you want to build a <td> inside a <div>? This is totally wrong.
– Sam