In this session we will do some logical task. We will create a pyramid pattern by the JavaScript. So before going forward you should have knowledge of loop in JavaScript.
Here will loop a variable which holds the number of pyramid stacks one above another and by the looping them we will print our pyramid. after this session you will be able to create your own login to create these type of logic’s.
Javascript
function printPyramid() {
var totalNumberofRows = 5;
var output = '';
for (var i = 1; i <= totalNumberofRows; i++) {
for (var j = 1; j <= i; j++) {
output += ' * ';
}
console.log(output);
output = '';
}
}
printPyramid();
Output
*
* *
* * *
* * * *
* * * * *
Conclusion
There are many pyramid stricture we can print just think and go forward to build your own login.
Thanks.