Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
Change colour of dynamic table in java
  1. the cells from the two diagonals shaded either orange or chartreuse;
  2. with the intersecting cell from the diagonals shaded black;
  3. and its text in white

There is a image here and that's what its suppose to look like.

This is what the table is suppose to look like at the end.

function drawTable() {
            var rows = parseInt(document.getElementById("numRows").value);
            var cols = parseInt(document.getElementById("numColumns").value);

            var theHtmlCode = "";

            theHtmlCode = "<table>";

            theHtmlCode += "<tr>";
            for ( var i=1 ; i<=cols ; i++ ) {
                theHtmlCode += "<th>";
                theHtmlCode += "Column " + i;
                theHtmlCode += "</th>";
            }
            theHtmlCode += "</tr>";



            // create table rows
            for ( var j=1 ; j<=rows ; j++ ) {
                theHtmlCode += "<tr>";

                // create table cells
                for ( var k=1 ; k<=cols ; k++ ) {

                    if (k==j)
                    {
                        theHtmlCode += "<td class='across'>";
                    }
                    else
                    {
                        theHtmlCode += "<td>";
                    }
                    theHtmlCode += j + "." + k;
                    theHtmlCode += "</td>";
                }

                theHtmlCode += "</tr>";
            }
            // close table tag
            theHtmlCode += "</table>";



            document.getElementById("whereTheTableGoes").innerHTML = theHtmlCode;

        }
body { background-color: lightblue}
        h1 {text-align: center}
        td { border: 2px blue solid}
        th { border: 3px red solid}
        img {border: 1px solid black}
        .across {background-color: pink}

      
        tr:nth-child(even) {background-color: #eb00ff;}
<label>How Many Rows Do You Want in the Table?</label>
<input type="number" min="1" id="numRows" placeholder="1 or more"> <br><br>
<label>How Many Columns Do You Want in the Table?</label>
<input type="number" min="1" id="numColumns" placeholder="1 or more"> <br><br>

<button onclick="drawTable()">Click to Draw the Table</button><br><br>

<div id="whereTheTableGoes"></div>

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda