Skip to content

Instantly share code, notes, and snippets.

@VanTigranyan
Created May 10, 2019 11:25
Show Gist options
  • Select an option

  • Save VanTigranyan/26219cd3d3053464ac9eb8726b312fa7 to your computer and use it in GitHub Desktop.

Select an option

Save VanTigranyan/26219cd3d3053464ac9eb8726b312fa7 to your computer and use it in GitHub Desktop.
Javascript-print pyramide with just one while loop.
function printPiramyde() {
let row = 1;
let col = 1;
let start = 5;
let end = 5;
while (row <= 5 && col <= 9) {
if ((col < start || col > end) && col !== 9) {
document.write('&nbsp;');
col += 1;
} else if (col === 9) {
if (row === 5) {
document.write('*');
} else {
document.write('&nbsp;<br>');
}
col = 1;
row += 1;
start -= 1;
end += 1;
} else {
document.write('*');
col += 1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment