Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: for-loop not working

I have this code right here.. where the variable num is the dimension of a n by n square table. The objective is to enter a number and create a table with the number as the dimension.

I got this code but it doesn't go through the 2 layers of for-loops. After the code execution, the string *change_text* just becomes: <table></table>

    change_text = "<table>";

    for (var i; i<num; i++) {
        change_text = change_text + "<tr>";
        for (var j; j<num; j++) {
            change_text = change_text + "<td> asdf </td>";

            //code for blue cells
        }
        change_text = change_text + "</tr>";
    }


    change_text = change_text+ "</table>"
like image 638
Kevin Lloyd Bernal Avatar asked Nov 24 '25 06:11

Kevin Lloyd Bernal


1 Answers

You need to initialize your iterators:

for(var i = 0; i < num; i++)
like image 100
Joe Avatar answered Nov 25 '25 19:11

Joe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!