LEVEL: Beginner
Whats in this post?
- Code
- Output
- Background and Explanation of the code
Code
To copy code: Click
<script>
{
var lines,i,j,k,temp;
var lines = prompt("Please enter the number of lines you want to print");
temp=lines;
for(i=1;i<=lines;i++)
{
for(j=1;j<=temp;j++)
{
document.write(i);
}
temp=temp-1;
document.write("<br/>");
}
}
</script>Background and Explanation of the code
- A JavaScript prompt box has been used to input the number of lines up to which the pattern will be printed.
- Two nested ‘for’ loops have been used to print the desired pattern. Variable ‘temp’ has been used for temporary storage.
Short URL: http://tinyit.cc/89e90

sending...