# Solved: Javascript: How to draw a pyramid?



## sepala

I want to design a pyramid like below using the javascript.
*
**
***
****
*****
This is the code which i used.
*
*

but this is not working. Can anyone write a code and explain that for me please? I am just a beginner, so please write a simple coding. Please help me. Thank you. ​


----------



## andythepandy

Hi,

This code should do it:



Code:


<script type="text/javascript" language="javascript">

document.write("<center>"); //write a center tag to make sure the pyramid displays correctly(try it without this step to see what happens)
for(var i = 0; i <= 10; i++) //a loop, this counts from 0 to 10 (how many rows of stars)
{
	for(var x = 0; x <= i; x++)// a loop, counting from 0 to whatever value i is currently on
	{
		document.write("*");//write a * character
	}
	document.write("<br/>"); //write a br tag, meaning new line, after every star in the row has been created
}
document.write("</center>"); //close the center tag, opened at the beginning

</script>

Hope that helps, if you need any more explaining just reply back

Andy


----------



## sepala

Thanks Andy...Your code really helped.


----------



## sepala

000


----------

