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
96 changes: 87 additions & 9 deletions starter_code/elevator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,95 @@ class Elevator {
this.floor = 0;
this.MAXFLOOR = 10;
this.requests = [];
this.interval = 0;
this.destinationFloor = 0;

this.waitingList = [];
this.passengers = [];
this.requests = [];
}

start() {
this.interval = setInterval( ()=> {
this.update()
},1000)
}

stop() {
clearInterval(this.interval);
}

update(x) {
this.log();
this._passengersEnter(x)

}
_passengersEnter(p) {

for (let i = 0; i < this.waitingList.length; i++)
if (p.originFloor === this.floor)
{
passengers.push(this.waitingList[i])
let temp = this.waitingList[i].name
this.requests.push(waitingList[i].destinationFloor)
console.log('Julia has enter the elevator')

for (let j = 0; j < this.passengers.length; i++)
{
if (this.passengers[j].name === this.waitingList[i].name)
this.waitingList.splice(i,1)
}
}
console.log(this.requests,this.waitingList,this.passengers)
}
_passengersLeave() {
for (let i = 0; i < this.passengers.length; i++)
if (this.passengers[i].destinationFloor === this.floor)
{
this.passengers[i].splice(i,1)
console.log('Julia has left the elevator')
}



start() { }
stop() { }
update() { }
_passengersEnter() { }
_passengersLeave() { }
floorUp() { }
floorDown() { }
call() { }
log() { }
}
floorUp() {
if (this.floor === this.MAXFLOOR) {
console.log('on est au MAX Chérie')
}
else this.floor += 1;

}
floorDown() {
if (this.floor === 0 ) {
console.log('on va au sous sol chérie ?')
}
else this.floor -= 1;
}

call(x) {
let movements = [];
movements.push(x);
//console.log(movements);
this.waitingList.push(x)
this.requests.push(x.originFloor)

//console.log(this.requests)
}

log() {
let data = {
floor: this.floor,
direction : 'up',
requests:[]
}
//console.log(data);
}
}



module.exports = Elevator;



Empty file added starter_code/index.html
Empty file.
12 changes: 12 additions & 0 deletions starter_code/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
const Elevator = require('./elevator.js');
const Person = require('./person.js');

var elevator = new Elevator();
var person = new Person("Max", 2,0);
var person2 = new Person("Ju", 9,0);
var person3 = new Person("BOB", 3,5);
elevator.call(person);
elevator.call(person2);
elevator.log();
elevator.update(person)
elevator.floorUp(person3)
elevator.update(person3)
3 changes: 3 additions & 0 deletions starter_code/person.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
class Person {
constructor(name, originFloor, destinationFloor){
this.name = name;
this.originFloor = originFloor;
this.destinationFloor = destinationFloor;
}
}

Expand Down