Pyramid Patterns – JavaScript – Part 4

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>=6-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>=6-i)
			{
				document.write("<td>"+j+"</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>=6-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++)
	{
		k=5;
		document.write("<tr>");
		for(j=1; j<=5; j++)
		{
			if(j>=6-i)
			{
				document.write("<td>"+k+"</td>");
				k--;
			}
			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++)
	{
		document.write("<tr>");
		for(j=1; j<=5; j++)
		{
			if(j>=6-i)
			{
				document.write("<td>"+j*i+"</td>");
			}
			else
			{
				document.write("<td>"+" "+"</td>");
			}
		}
		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<=5; j++)
		{
			if(j>=6-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 7:

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

Pattern 10:

<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>=5-i)
			{
				document.write("<td width='18px' align='center'>"+k+"</td>");
				k++;
			}
			else
			{
				document.write("<td width='18px'>"+" "+"</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>=6-i)
			{
				if(j % 2 == 0)
				{
					if(i%2==0)
					{
						document.write("<td width='15px'>"+"*"+"</td>");
					}
					else
					{
						document.write("<td width='15px'>"+1+"</td>");
					}
				}
				else
				{
					document.write("<td width='15px'>"+0+"</td>");
				}
			}
			else
			{
				document.write("<td width='12px'>"+" "+"</td>");
			}
		}
		document.write("</tr>");
	}
	document.write("</table>");
</script>

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 *