Skip to content

Instantly share code, notes, and snippets.

@kavitshah8
Last active November 28, 2018 13:21
Show Gist options
  • Save kavitshah8/7509a6803418e39ccfc6 to your computer and use it in GitHub Desktop.
Save kavitshah8/7509a6803418e39ccfc6 to your computer and use it in GitHub Desktop.
Pyramid Patterns
"use strict";
function createHalfPyramid (height) {
for (var i = 1; i <= height; i++) {
var row = '';
for (var j = 1; j <= (height - i); j++) {
row += ' ';
}
for (var k = 1; k <= i; k++) {
row += '*';
}
console.log(row);
}
}
createHalfPyramid(5);
"use strict";
function createHalfPyramid (height) {
for (var i = 1; i <= height; i++) {
var row = '';
for (var j = 1; j <= (height - i + 1); j++) {
row += '*';
}
console.log(row);
}
}
createHalfPyramid(5);
"use strict";
function createHalfPyramid (height) {
for (var i = 1; i <= height; i++) {
var row = '';
for (var j = 1; j <= (i - 1); j++) {
row += ' ';
}
for (var j = 1; j <= (height - i + 1); j++) {
row += '*';
}
console.log(row);
}
}
createHalfPyramid(5);
"use strict";
function createHalfPyramid (height) {
for (var i = 1; i <= height; i++) {
var row = '';
for (var j = 1; j <= i; j++) {
row += '*';
}
console.log(row);
}
}
createHalfPyramid(5);
@rahul3103
Copy link

rahul3103 commented Nov 28, 2018

for (var line = '*'; line.length < n; line += '*') console.log(line);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment