Commit b9ec288c authored by Nurasyl's avatar Nurasyl

5 task

parent 7e16a42e
const elevator = {
minFloor: 1,
maxFloor: 16,
currentFloor: 1,
toFloor: function(number) {
if(number > this.currentFloor) {
this.printFloor();
for(let i = this.currentFloor; i < number; i++) {
this.upOneFloor();
};
} else {
this.printFloor();
for(let i = this.currentFloor; i > number; i--) {
this.downOneFloor();
};
};
},
printFloor: function() {
console.log(`Этаж ${this.currentFloor}`);
},
upOneFloor : function() {
if(this.currentFloor < this.maxFloor) {
this.currentFloor++;
this.printFloor();
} else {
console.log("Там самолеты.");
}
},
downOneFloor: function() {
if((this.currentFloor - 1) > this.minFloor) {
this.currentFloor--;
this.printFloor();
} else {
console.log("В аду нет лифтов");
}
}
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment