Last active
November 28, 2018 13:21
-
-
Save kavitshah8/7509a6803418e39ccfc6 to your computer and use it in GitHub Desktop.
Pyramid Patterns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for (var line = '*'; line.length < n; line += '*') console.log(line);