Skip to content
Open
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
79 changes: 64 additions & 15 deletions starter_code/elevator.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,68 @@
class Elevator {
constructor(){
this.floor = 0;
this.MAXFLOOR = 10;
this.requests = [];
}

start() { }
stop() { }
update() { }
_passengersEnter() { }
_passengersLeave() { }
floorUp() { }
floorDown() { }
call() { }
log() { }
constructor() {
this.floor = 0;
this.MAXFLOOR = 10;
this.requests = [];
this.direction = "";
}

start() {
var intervalID = setInterval(update, 1000);
}

stop() {
clearInterval(intervalID);
}
update() {

this.log();
}
_passengersEnter() {}
_passengersLeave() {}
floorUp() {
if (this.floor < this.MAXFLOOR) {
this.floor += 1;
this.direction = "UP";
}
return this.floor;

}
floorDown() {
if (this.floor > 0) {
this.floor -= 1;
this.direction = "DOWN";
}
return this.floor;
}
call(person) {
this.requests.push(person);
}
log() {
console.log("Direction : " + this.direction + "| floor: " + this.floor);
}
}

module.exports = Elevator;

lift = new Elevator; //create a object;
for (let i = 0; i < lift.MAXFLOOR + 1; i++) {
lift.floorUp();

lift.update();
}
for (let i = lift.MAXFLOOR; i > -2; i--) {
lift.floorDown();
lift.update();
}
// for(let i = 0; i > lift.floor ;)

class Person {
constructor(name, originFloor, destFloor)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are missing the curly braces to open the constructor block {
and close it latet }

this.name = name;
this.originFloor = originFloor;
this.destFloor = destFloor;

}

tom = new Person;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These last two lines could probably go in your index.js file, so you can asynchronously call index.js with node

lift.call(tom);