Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I see a number of problems here. First and foremost, I don't believe your code is properly balanced. I believe as a first step it should look more like:</p> <pre><code>&lt;script language="javascript"&gt; document.write('&lt;table border = \"3\"&gt;'); while(i &lt;= y) { document.write('&lt;tr&gt;'); j = 0; while(j &lt;= x) { if (i == 0) { if (j == 0) { document.write(' &lt;th&gt;&lt;/th&gt; '); } else { document.write('&lt;th&gt;'); document.write("x = " + j); document.write('&lt;/th&gt;'); } } else { if (j == 0) { document.write('&lt;th&gt;'); document.write("y = " + i); document.write('&lt;/th&gt;'); } else { document.write('&lt;td&gt;'); document.write(operation(i,j)); document.write('&lt;/td&gt;'); } } j++; } document.write('&lt;/tr&gt;'); i++; } document.write('&lt;/table&gt;'); &lt;/script&gt; </code></pre> <p>Secondarily it looks to me like you're never really ever instantiating i, and while you do it with j, you're not doing it early enough.</p> <p>At the line while(i &lt;= y) the interpreter is basically seeing:</p> <pre><code>while (undefined &lt;= undefined) { </code></pre> <p>At some level, I'm honestly not sure that document.writes is really the best solution for you, I would probably recommend using document.createElement instead, but that's perhaps more of a personal preference.</p> <p>Attempting to step a level further out yet sticking with your methodology, I might look toward something like:</p> <pre><code>function generateTable (width, height) { document.write("&lt;table border=\"3\"&gt;"); var i = 1; while (i &lt;= height) { document.write("&lt;tr&gt;"); var j = 1; while (j &lt;= width) { if (i == 0) { // header row document.write("&lt;th&gt;"+ j +" x "+ i +"&lt;/th&gt;"); } else { document.write("&lt;td&gt;"+ j +" x "+ i +"&lt;/td&gt;"); } j++; } document.write("&lt;/tr&gt;"); i++; } document.write("&lt;/table&gt;"); } generateTable(5, 10); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload