Created
July 15, 2019 13:48
-
-
Save maurer2/075939aa94a4de63d9e857500a4e1087 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function pyramid(height) { | |
// row loop | |
for(let i = 0; i< height; i++) { | |
const whitespaces = height - (i + 1); | |
const stars = (2 * i) + 1; | |
const characters = ' '.repeat(whitespaces) + '*'.repeat(stars); | |
console.log(characters); | |
} | |
} | |
pyramid(3); | |
pyramid(4); | |
/* | |
3 | |
* | |
*** | |
***** | |
4 | |
* | |
*** | |
***** | |
******* | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment