JavaScript program to print Pyramid with numbers
Following program shows you how to print pyramid with numbers using for loop
function createPyramidWithNumbers() {
let numberofRows = 5;
let result='';
for (var i = 1; i <= numberofRows; i++) {
for (var j = 1; j <= i; j++) {
result += j + ' ';
}
console.log(result);
result = '';
}
};
createPyramidWithNumbers();
Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Try it Online here https://onecompiler.com/javascript/3x5quxzhz