Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions starter_code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
66 changes: 52 additions & 14 deletions starter_code/elevator.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,57 @@
class Elevator {
constructor(){
this.floor = 0;
this.MAXFLOOR = 10;
this.requests = [];
constructor() {
this.floor = 0;
this.MAXFLOOR = 10;
this.requests = [];
this.direction = "up";
this.interval;
}

start() { }
stop() { }
update() { }
_passengersEnter() { }
_passengersLeave() { }
floorUp() { }
floorDown() { }
call() { }
log() { }
start() {
//comprueba con el comprueba el floor y si esta en maxfloor no aumenta mas y baja
this.interval = setInterval(() => {
/* if (this.floor < this.MAXFLOOR && this.direction == "up") {

this.floorUp()
} else if(this.floor >= 0 && this.direction == "down") {
this.floorDown()

} */
this.floorUp();
this.update();
}, 1000);
}

stop() {}
update() {
return this.log();
}
_passengersEnter() {}
_passengersLeave() {}
floorUp() {
if (this.floor < this.MAXFLOOR && this.direction === 'up') {
this.floor++;
} else {
this.direction = 'down';
this.floorDown();

}
}
floorDown() {
if (this.floor > 0 && this.direction == 'down') {
this.floor--;
} else {
this.direction = "up";
this.floorUp();
}

}
call() {}
log() {
console.log(`Direction: ${this.direction} / Floor: ${this.floor}`);


}
}

module.exports = Elevator;
module.exports = Elevator;
2 changes: 2 additions & 0 deletions starter_code/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
const Elevator = require('./elevator.js');
const elevator1= new Elevator();
elevator1.start();