From 955d545a27e594deaee9918e8ef82ade5b1cdcb0 Mon Sep 17 00:00:00 2001 From: pabloonieva Date: Sun, 17 Dec 2017 16:30:27 +0100 Subject: [PATCH 1/2] Exercise started --- starter_code/elevator.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/starter_code/elevator.js b/starter_code/elevator.js index 5339f35..d687600 100644 --- a/starter_code/elevator.js +++ b/starter_code/elevator.js @@ -5,15 +5,23 @@ class Elevator { this.requests = []; } - start() { } - stop() { } - update() { } + start() { + var interval = setInterval(this.update(),1000); + } + stop() { + clearInterval(interval); + } + update() { + this.log(); + } _passengersEnter() { } _passengersLeave() { } floorUp() { } floorDown() { } call() { } - log() { } + log() { + console.log("Direction: " + this.requests + " | Floor: " + this.floor); + } } module.exports = Elevator; From f26c8844ba7c62df0e6ba7ed860ef03b8153b3e5 Mon Sep 17 00:00:00 2001 From: pabloonieva Date: Sun, 17 Dec 2017 17:06:08 +0100 Subject: [PATCH 2/2] 2nd commit. feat: floorUp/Down functions --- starter_code/elevator.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/starter_code/elevator.js b/starter_code/elevator.js index d687600..1b7c158 100644 --- a/starter_code/elevator.js +++ b/starter_code/elevator.js @@ -1,25 +1,35 @@ -class Elevator { +class Elevator{ constructor(){ this.floor = 0; this.MAXFLOOR = 10; this.requests = []; } - start() { + start(){ var interval = setInterval(this.update(),1000); } - stop() { + stop(){ clearInterval(interval); } - update() { + update(){ this.log(); } _passengersEnter() { } _passengersLeave() { } - floorUp() { } - floorDown() { } - call() { } - log() { + floorUp(){ + if(this.floor < this.MAXFLOOR){ + this.floor += 1; + } + } + floorDown(){ + if(this.floor > 0){ + this.floor -= 1; + } + } + call(){ + + } + log(){ console.log("Direction: " + this.requests + " | Floor: " + this.floor); } }