JavaScript tutorial 73 – Print pyramid patterns of numbers and stars
Print pyramid patterns of numbers and stars
Displaying patterns using javascript nested for loop:
var rows=5;
for(var i=1;i<=rows;i++)
{
for(var j=1;j<=i;j++)
{
document.write(” * “);
}
document.write(“<br/>”);
}
Output:
*
* *
* * *
* * * *
* * * * *
Displaying pyramid using for loop:
var rows = 5;
for(var i=1; i<=rows; i++)
{
for(var k=1; k<=( rows-i ); k++)
{
document.write(” “);
}
for(var j=1; j<=i; j++)
{
document.write(“* “);
}
document.write(“<br/>”);
}
Output:
*
* *
* * *
* * * *
* * * * *
=========================================
Follow the link for next video:
JavaScript tutorial 74 – function declaration | functions in javascript
Follow the link for previous video:
JavaScript tutorial 72 – Print patterns of numbers and stars
====== JavaScript Questions & Answers ========
=========================================
Original source
31 responses to “JavaScript tutorial 73 – Print pyramid patterns of numbers and stars”
SUBSCRIBE, SHARE & SUPPORT:
https://www.youtube.com/chidrestechtutorials
VISIT & LEARN AT FREE OF COST:
https://www.chidrestechtutorials.com
Amazing
Thank you for this video, sir.
Although the code works, the time complexity is fucked up!!
Oh my god looping working like this ahh. Thanks bro
Please start your branch in chennai. Sir
Now this is some good content
Thank you for the explanation. Great Job!
Thank you so much for this long but really clear explanation I never understood how nested for loops worked but since you went over every single bit of code I now understand it completly. Thank you and god bless you sir.
my god this is crystal clear thank you!
your explanation is the best sir, thank you so much.
Awesome explanation🙏🙏
nice video
can you please make a tutorial for pascal triangle..plz
it was elaborate and easy to understand. Really liked the explanation.
hi i want to learn full pyramid in java script can you posted video ?
Thank you, good explanation!
This is really good, the explanation is very informative.
finally got the solution for the number pattern here.. thanks alot
Nice video
thanks for explanation nicely
I have been searching non-stop for nested for loop explanation and this is the only video that really explained how to get the result. THANK YOU FOR THIS!!!!!!!!!!
Nice one.
one question in my mind, how the logic coming to your mind, i am not getting in my mind
Great job explaining this!
So much patience walking us through the whole process.
Very much appreciated!
how could we do dynamically by Input element
Very nice
great explanation buddy!!!
<html>
<body>
<h2>JavaScript Loops</h2>
<script>
var rows = 5;
var cols = 5;
for (var i = 1; i <rows; i++) {
for (var k = 1; k<=(rows-i); k++){
document.write(" ");
}
for (var j = 1; j <=i; j++) {
document.write("*");
}
document.write("<br>");
}
</script>
</body>
</html>
<!– // OUT PUT
JavaScript Loops
*
**
*
**
// –>
Can i make the pyramid face down with the decrement loop pls help
Hey here's mine and there is no pyramid`
var rows = 5
// var cols = 5
for (var i = 1; i <= rows; i++) {
for (var k = 1; i <= ( rows-i ); k++){
document.write(" ")
}
for (var j = 1; j <= i; j++) {
document.write("* ");
}
document.write("<br>");
}
incorrect code posted in description. this is the pyramid one:
<script type= "text/javascript">
var rows = 5;
for(var i=1; i<=rows; i++)
{
for(var k=1; k<=( rows-i ); k++)
{
document.write(" ");
}
for(var j=1; j<=i; j++)
{
document.write("* ");
}
document.write("<br/>");
}