Created
May 10, 2019 11:25
-
-
Save VanTigranyan/26219cd3d3053464ac9eb8726b312fa7 to your computer and use it in GitHub Desktop.
Javascript-print pyramide with just one while loop.
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 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(' '); | |
| col += 1; | |
| } else if (col === 9) { | |
| if (row === 5) { | |
| document.write('*'); | |
| } else { | |
| document.write(' <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