0

There is an extra row on top and on the side of 1-10 that I don't want on my table. How can I remove this?

<script type="text/javascript">
/* <![CDATA[ */

var numRows = "10";
var numCols = "10";
if (isNaN(numRows) || isNaN(numCols)) {
}else {
    var tblHTML = "", rowHTML;
    for (var row = 0; row <= numRows; row++) {
        rowHTML = "";
        for (var col = 0; col <= numCols; col++) {
            if (row == 0) {
                rowHTML += "<td>" +
                    ((col == 0) ? " " : col) +
                    "</td>";
            } else if (col == 0) {
                rowHTML += "<td>" +
                    row +
                    "</td>";
            } else {
                rowHTML += "<td>" +
                    (row * col) +
                    "</td>";
            }
        }
        tblHTML += "<tr>" + rowHTML + "</tr>";
    }
    document.write("<table cellpadding=\"5\" border=\"0\">" + tblHTML + "</table>");
}

/* ]]> */
</script>
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Airshow
0

Your two nested loops both iterate from 0-10; ie. 11 iterations.

For 10 rows/columns, either iterate from 0-9 or 1-10.

Airshow

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.