Note that there are some explanatory texts on larger screens.

plurals
  1. POThis html code is making me crazy
    text
    copied!<pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;DIsplaying triangle /square&lt;/title&gt; &lt;script type="text/javascript"&gt; document.write("&lt;html&gt;&lt;body&gt;&lt;p style='line-height:100%;&gt;"); var sides=prompt("Enter the number of sides","3/4"); if(sides==4) { var i=0; var j=0; var z=0; while(i&lt;=6) { if(i==0||i==6) { while(j&lt;=6) { document.write("*"); document.write("&lt;span style='visibility:hidden'&gt;*&lt;/span&gt;"); ++j; } j=0; document.write("&lt;br\&gt;"); } else { while(z&lt;=6) { if(z==0||z==6) { document.write("*"); document.write("&lt;span style='visibility:hidden'&gt;*&lt;/span&gt;"); } else { document.write("&lt;span style='visibility:hidden'&gt;*&lt;/span&gt;"); document.write("&lt;span style='visibility:hidden'&gt;*&lt;/span&gt;"); } ++z; } z=0; document.write("&lt;br\&gt;"); } ++i; } document.write("&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;"); } else { var i=0; } &lt;/script&gt; &lt;/head&gt; &lt;/html&gt; </code></pre> <p>The output when I enter <code>4</code> in the prompt box is supposed to be:</p> <pre><code>* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * </code></pre> <p>(Consider it a perfect square. Its tough to draw it here.)</p> <p>but I get:</p> <pre><code>** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * </code></pre> <p>Look at the first line. It has first 2 "*"s together. As per the code it is not supposed to happen. Something is going wrong in the <code>document.write("*")</code> part. When I tried debugging using <code>alert</code> what I found out is that the first time (i.e when i=0) the first <code>document.write("*")</code> gets ignored. But every other time it is considered.</p>
 

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