Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!