Here is the code to display PYRAMID but its not exactly producing required output.
function generatePyramid() {
var totalNumberofRows = 5;
var arr = new Array();
for (var i = 1; i <= totalNumberofRows; i++) {
for (var j = 1; j <= i; j++) {
arr.push(j);
console.log(j);
}
console.log("\n");
}
}
Another Option
One line of code:
You can FRAME for loop conditions for any patterns given either it may be triangle, right angled triangle,inverse triangle etc.. For more info refer the below code and workbook image
//1, 3, 5,7,9.. ---> Odd number series (stars) appear in pyramid pattern //1, 2, 3,4,5.. ----> Counter (number of rows)
//For every each counter there exist 2*n-1 value
} pyramid(5);
For your requirement , code is below
} generateNumberTriangle(7);
You should generate an array on every row iteration and output it at the end:
This could be done using a single for loop.
This will create a proper pyramid in a console.
Here's a simple solution using ES6 syntax