Answer

Answer

t.me/js_test

Ответ:

const ladder = {
    step: 0,
    up() {
        this.step++;
        return this;
    },
    down() {
        this.step--;
        return this;
    },
    showStep() {
        console.log(this.step);
        return this;
    },
};

Объяснение:

В методе up увеличиваем this.step на один, в методе down уменьшаем, в методе showStep выводим this.step в консоль. В каждом из методов возвращаем this что-бы работал вызов по цепочке.

Код для проверки:

const ladder = {
    step: 0,
    up() {
        this.step++;
        return this;
    },
    down() {
        this.step--;
        return this;
    },
    showStep() {
        console.log(this.step);
        return this;
    },
};

ladder.up();
ladder.up();
ladder.down();
ladder.showStep(); // 1
ladder.down();
ladder.showStep(); // 0

ladder.up().up().down().showStep().down().showStep(); // 1 0

Report Page