Guest User

Untitled

a guest
Jul 18th, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //https://zero.p2p.shpp.me/tasks/3_5_christmas_tree.html
  2. // row - рядок виводу
  3. // column - колонка виводу;
  4. let height = +prompt("Який розмір ялинки?");//висота
  5. let width = 2 * height + 1;// ширина
  6. let star = '*';
  7. let space = ' ';
  8. for (let row = 0; row <= height; row++) {
  9.     if (height == 0) break;
  10.  
  11.     let stars_count = 1 + 2 * row;//кількість зірок
  12.     if (row == height) {
  13.         stars_count = 1;
  14.     }
  15.  
  16.     let spaces_count = width - stars_count;
  17.     for (let i = 0; i < spaces_count / 2; i++) {
  18.         console.put(space);
  19.     }
  20.     for (let i = 0; i < stars_count; i++) {
  21.         console.put(star);
  22.     }
  23.     for (let i = 0; i < spaces_count / 2; i++) {
  24.         console.put(space);
  25.     }
  26.     console.log();
  27. }
Advertisement
Add Comment
Please, Sign In to add comment