xxxxxxxxxx
function generatePyramid() {
var totalNumberofRows = 5;
var output = '';
for (var i = 1; i <= totalNumberofRows; i++) {
for (var j = 1; j <= i; j++) {
output += j + ' ';
}
console.log(output);
output = '';
}
} generatePyramid();
xxxxxxxxxx
// Display pyramid of number using JavaScript
function pyramid(n) {
for (let i = 1; i <= n; i++) {
let str = ' '.repeat(n - i);
let str2 = '*'.repeat(i * 2 - 1);
console.log(str + str2 + str);
}
}
pyramid(5);
star pyramid
xxxxxxxxxx
for(i=0;i < 9;i++){
for(j=0;j < i; j++){
dot=document.createElement("SPAN")
dot.innerText = "*";
dot.id='d'+i;
dot.style.position="absolute";
document.body.appendChild(dot);
dot.style.left=i*12+"px";
dot.style.top=(6+j)*12+"px";
}
}