Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://zero.p2p.shpp.me/tasks/3_5_christmas_tree.html
- // row - рядок виводу
- // column - колонка виводу;
- let height = +prompt("Який розмір ялинки?");//висота
- // let width = 2 * height + 1;// ширина
- let star = '*'; // good deсision
- let space = ' '; // good deсision
- let stars_count = 1 // починаємо з однієї зірки та
- let spaces_count = height - 1; // та з такої кількості пробілів (по вашой формулі наче так само вийде)
- for (let row = 0; row < height; row++) {
- // if (height == 0) break;
- // let stars_count = 1 + 2 * row;//кількість зірок
- /*if (row == height) {
- stars_count = 1;
- }*/
- // let spaces_count = width - stars_count;
- for (let i = 0; i < spaces_count; i++) {
- console.put(space); // left spaces
- }
- for (let i = 0; i < stars_count; i++) {
- console.put(star); // stars
- }
- for (let i = 0; i < spaces_count; i++) {
- console.put(space); // right spaces if require (e.g. codewars)
- }
- console.log();
- stars_count += 2;
- spaces_count -= 1;
- }
- // draw a trunk here
Add Comment
Please, Sign In to add comment