Pyramid Patterns – JavaScript – Part 3

Pattern 1:

<script type="text/javascript">
	document.write("<table>");
	for(i=1; i<=5; i++)
	{
		document.write("<tr>");
		for(j=1; j<=6-i; j++)
		{
			document.write("<td>"+"*"+"</td>");
		}
		document.write("</tr>");
	}
	document.write("</table>");
</script>

Pattern 2:

<script type="text/javascript">
	document.write("<table>");
	for(i=1; i<=5; i++)
	{
		document.write("<tr>");
		for(j=1; j<=6-i; j++)
		{
			document.write("<td>"+i+"</td>");
		}
		document.write("</tr>");
	}
	document.write("</table>");
</script>

Pattern 3:

<script type="text/javascript">
	document.write("<table>");
	for(i=1; i<=5; i++)
	{
		document.write("<tr>");
		for(j=1; j<=6-i; j++)
		{
			document.write("<td>"+j+"</td>");
		}
		document.write("</tr>");
	}
	document.write("</table>");
</script>

Pattern 4:

<script type="text/javascript">
	document.write("<table>");
	for(i=1; i<=5; i++)
	{
		k=5;
		document.write("<tr>");
		for(j=1; j<=6-i; j++)
		{
			document.write("<td>"+k+"</td>");
			k--;
		}
		document.write("</tr>");
	}
	document.write("</table>");
</script>

Pattern 5:

<script type="text/javascript">
	document.write("<table>");
	for(i=1; i<=5; i++)
	{
		document.write("<tr>");
		for(j=1; j<=6-i; j++)
		{
			k=i*j;
			document.write("<td>"+k+"</td>");
		}
		k++;
		document.write("</tr>");
	}
	document.write("</table>");
</script>

Pattern 6:

<script type="text/javascript">
	document.write("<table>");
	for(i=1; i<=5; i++)
	{
		document.write("<tr>");
		for(j=1; j<=6-i; j++)
		{
			k=j*j;
			document.write("<td>"+k+"</td>");
		}
		k++;
		document.write("</tr>");
	}
	document.write("</table>");
</script>

Pattern 7:

<script type="text/javascript">
	document.write("<table>");
	for(i=1; i<=5; i++)
	{
		document.write("<tr>");
		for(j=1; j<=6-i; j++)
		{
			k=i*i;
			document.write("<td>"+k+"</td>");
		}
		k++;
		document.write("</tr>");
	}
	document.write("</table>");
</script>

Pattern 8:

<script type="text/javascript">
	document.write("<table>");
	for(i=1; i<=5; i++)
	{
		document.write("<tr>");
		for(j=1; j<=6-i; j++)
		{
			if(j % 2 == 1)
			{
				document.write("<td>"+i+"</td>");
			}
			else
			{
				document.write("<td>"+"*"+"</td>");
			}
		}
		document.write("</tr>");
	}
	document.write("</table>");
</script>

Pattern 9:

<script type="text/javascript">
	document.write("<table>");
	for(i=1; i<=5; i++)
	{
		document.write("<tr>");
		for(j=1; j<=6-i; j++)
		{
			if(j % 2 == 1)
			{
				document.write("<td>"+i+"</td>");
			}
			else
			{
				document.write("<td>"+"*"+"</td>");
			}
		}
		document.write("</tr>");
	}
	document.write("</table>");
</script>

Pattern 10:

<script type="text/javascript">
	document.write("<table>");
	for(i=1; i<=5; i++)
	{
		document.write("<tr>");
		for(j=1; j<=6-i; j++)
		{
			if(j % 2 == 0)
			{
				if(i%2==0)
				{
					document.write("<td>"+"*"+"</td>");
				}
				else
				{
					document.write("<td>"+1+"</td>");
				}
			}
			else
			{
				document.write("<td>"+0+"</td>");
			}
		}
		document.write("</tr>");
	}
	document.write("</table>");
</script>

Pattern 11:

<script type="text/javascript">
	document.write("<table>");
	for(i=1; i<=5; i++)
	{
		document.write("<tr>");
		for(j=1; j<=6-i; j++)
		{
			if(i % 2 == 1)
			{
				if(j%2==0)
				{
					document.write("<td>"+"*"+"</td>");
				}
				else
				{
					document.write("<td>"+"!"+"</td>");
				}
			}
			else
			{
				document.write("<td>"+"*"+"</td>");
			}
		}
		document.write("</tr>");
	}
	document.write("</table>");
</script>

Pattern 12:

<script type="text/javascript">
	document.write("<table>");
	k=1;
	for(i=1; i<=5; i++)
	{
		document.write("<tr>");
		for(j=1; j<=6-i; j++)
		{
			document.write("<td width=18px>"+k+"</td>");
			k++;
		}
		document.write("</tr>");
	}
	document.write("</table>");
</script>

Pyramid 13:

<script type="text/javascript">
	document.write("<table>");
	for(i=1; i<=5; i++)
	{
		document.write("<tr>");
		for(j=1; j<=6-i; j++)
		{
			if(i==1 && j==1 || i==5 || j==5)
			{
				document.write("<td width=18px>"+"@"+"</td>");
			}
			else
			{
				document.write("<td width=18px>"+"*"+"</td>");
			}
		}
		document.write("</tr>");
	}
	document.write("</table>");
</script>

… to be continued to the next part (Part 4)

DEAR READERS,
If you know some more patterns of this type and want them to be published, comment them above, we will post them.

Leave a Reply

Your email address will not be published. Required fields are marked *