Note that there are some explanatory texts on larger screens.

plurals
  1. POchanging 2 random numbers in 30 times in number table using java script
    primarykey
    data
    text
    <p>In this code each time you open the html page two random numbers are generated and thier location in the matrix will be changed. for example the random numbers are 2,8 in the main table 2 is in the matrix[0][1],matrix[1][7],matrix[2][4],matrix[3][0],matrix[4][6],matrix[5][3],matrix[6][8],matrix[3][0],matrix[7][5] ,matrix[8][2] .in the result table 8 is set in these location and 2 is set in the current locations of 8. I want to repeat this, 30 times.</p> <p>so far I have :</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang="en" xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;body&gt; &lt;script type="text/javascript"&gt; var matrix = new Array(); matrix[0]=[1,2,3,4,5,6,7,8,9]; matrix[1]=[4,5,6,7,8,9,1,2,3]; matrix[2]=[7,8,9,1,2,3,4,5,6]; matrix[3]=[2,3,4,5,6,7,8,9,1]; matrix[4]=[5,6,7,8,9,1,2,3,4]; matrix[5]=[8,9,1,2,3,4,5,6,7]; matrix[6]=[3,4,5,6,7,8,9,1,2]; matrix[7]=[6,7,8,9,1,2,3,4,5]; matrix[8]=[9,1,2,3,4,5,6,7,8]; document.writeln('&lt;table border="1"&gt;'); for (i = 0; i &lt; 9; i++) { document.writeln('&lt;tr&gt;'); for (j = 0; j &lt; 9; j++) document.writeln('&lt;td&gt;' + matrix[i][j] + '&lt;/td&gt;'); document.writeln('&lt;/tr&gt;'); } document.writeln('&lt;/table&gt;'); document.writeln('&lt;table border="1"&gt;'); document.writeln("The random numbers are:"); document.writeln('&lt;br&gt;'); var r1 = Math.ceil(Math.random() * 9); var r2 = Math.ceil(Math.random() * 9); document.writeln(r1); document.writeln(r2); document.writeln('&lt;br&gt;'); document.writeln("The result table is:"); for(i=0; i&lt;9; i++) { document.writeln('&lt;tr&gt;'); for(j=0; j&lt;9; j++) { if(matrix[i][j]==r1) { matrix[i][j]=r2; document.writeln('&lt;td&gt;' + matrix[i][j] + '&lt;/td&gt;'); } else if(matrix[i][j]!=r1 &amp;&amp; matrix[i][j]!=r2) document.writeln('&lt;td&gt;' + matrix[i][j] + '&lt;/td&gt;'); else if(matrix[i][j]==r2) { matrix[i][j]=r1; document.writeln('&lt;td&gt;' + matrix[i][j] + '&lt;/td&gt;'); } } document.writeln('&lt;/tr&gt;'); } document.writeln('&lt;/table&gt;'); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </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. 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