Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DE MAD]Alberto Sánchez #234

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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();