Skip to content

Instantly share code, notes, and snippets.

@maurer2
Created July 15, 2019 13:48
Show Gist options
  • Save maurer2/075939aa94a4de63d9e857500a4e1087 to your computer and use it in GitHub Desktop.
Save maurer2/075939aa94a4de63d9e857500a4e1087 to your computer and use it in GitHub Desktop.
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