Pyramid Patterns – JavaScript – Part 2

Pattern 1:

<script type="text/javascript">
	document.write("<table>");
	for(i=1; i<=5; i++)
	{
		document.write("<tr>");
		for(j=1; j<=5; j++)
		{
			if(j>=i)
			{
				document.write("<td>"+"*"+"</td>");
			}
			else
			{
				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<=5; j++)
		{
			if(j>=i)
			{
				document.write("<td>"+i+"</td>");
			}
			else
			{
				document.write("<td>"+" "+"</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<=5; j++)
		{
			if(j>=i)
			{
				document.write("<td>"+i+"</td>");
			}
			else
			{
				document.write("<td>"+" "+"</td>");
			}
		}
		document.write("</tr>");
	}
	document.write("</table>");
</script>

Pattern 4:

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

Pattern 5:

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

Pattern 6:

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

Pattern 12:

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

Pattern 13:

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

Pattern 14:

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

Pattern 15:

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

Pattern 16:

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

Pattern 17:

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

Pattern 18:

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

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

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 *