View difference between Paste ID: DrA5U2j4 and XAdLj4ic
SHOW: | | - or go back to the newest paste.
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;// ширина
5+
// let width = 2 * height + 1;// ширина
6-
let star = '*';
6+
let star = '*'; // good deсision
7-
let space = ' ';
7+
let space = ' '; // good deсision 
8-
for (let row = 0; row <= height; row++) {
8+
let stars_count = 1 // починаємо з однієї зірки та
9-
    if (height == 0) break;
9+
let spaces_count = height - 1; // та з такої кількості пробілів (по вашой формулі наче так само вийде)
10
for (let row = 0; row < height; row++) {
11-
    let stars_count = 1 + 2 * row;//кількість зірок
11+
   // if (height == 0) break;
12-
    if (row == height) {
12+
 
13
    // let stars_count = 1 + 2 * row;//кількість зірок
14
    /*if (row == height) {
15
        stars_count = 1;
16-
    let spaces_count = width - stars_count;
16+
    }*/
17-
    for (let i = 0; i < spaces_count / 2; i++) {
17+
 
18-
        console.put(space);
18+
    // let spaces_count = width - stars_count;
19
    for (let i = 0; i < spaces_count; i++) {
20
        console.put(space); // left spaces
21-
        console.put(star);
21+
22
    for (let i = 0; i < stars_count; i++) {
23-
    for (let i = 0; i < spaces_count / 2; i++) {
23+
        console.put(star); // stars
24-
        console.put(space);
24+
25
    for (let i = 0; i < spaces_count; i++) {
26
        console.put(space); // right spaces if require (e.g. codewars)
27-
}
27+
28
    console.log();
29
30
    stars_count += 2;
31
    spaces_count -= 1;
32
}
33
// draw a trunk here