Commit 44d9e905 authored by Muhammad Ameen's avatar Muhammad Ameen 💻

issue fix

parent fc7bfc24
...@@ -22,7 +22,9 @@ ...@@ -22,7 +22,9 @@
</div> </div>
<div class="floorBox"> <div class="floorBox">
<div class="lift" id="liftBox"></div> <div class="lift" id="liftBox">
</div>
</div> </div>
</div> </div>
......
...@@ -10,15 +10,14 @@ let btn0 = document.getElementById("btn0"), ...@@ -10,15 +10,14 @@ let btn0 = document.getElementById("btn0"),
function command(floorNo) { function command(floorNo) {
let checkNumber = floorArr.includes(floorNo); let checkNumber = floorArr.includes(floorNo);
if (checkNumber === false) { if (checkNumber === false && currentFloor !== floorNo) {
floorArr.push(floorNo); floorArr.push(floorNo);
floorsArrP.innerHTML = floorArr; floorsArrP.innerHTML = floorArr;
} }
if (floorArr.length === 1) {
move();
}
switch (floorNo) { for (var i = 0; i < floorArr.length; i++) {
if (floorArr[i] !== currentFloor) {
switch (floorArr[i]) {
case 0: case 0:
btn0.style.backgroundColor = "red"; btn0.style.backgroundColor = "red";
break; break;
...@@ -38,14 +37,20 @@ function command(floorNo) { ...@@ -38,14 +37,20 @@ function command(floorNo) {
default: default:
break; break;
} }
}
}
console.log(floorArr); console.log(floorArr);
if (floorArr.length === 1) {
move();
}
} }
function move() { function move() {
if (floorArr[0] === 0) { if (floorArr[0] === 0) {
liftBox.style.marginTop = "680px"; liftBox.style.marginTop = "680px";
liftBox.style.transition = "5s"; liftBox.style.transition = "5s";
currentFloor = 0;
setTimeout(() => { setTimeout(() => {
if (floorArr.length !== 0) { if (floorArr.length !== 0) {
floorArr.splice(0, 1); floorArr.splice(0, 1);
...@@ -57,7 +62,7 @@ function move() { ...@@ -57,7 +62,7 @@ function move() {
} else if (floorArr[0] === 1) { } else if (floorArr[0] === 1) {
liftBox.style.marginTop = "544px"; liftBox.style.marginTop = "544px";
liftBox.style.transition = "5s"; liftBox.style.transition = "5s";
currentFloor = 1;
setTimeout(() => { setTimeout(() => {
if (floorArr.length !== 0) { if (floorArr.length !== 0) {
floorArr.splice(0, 1); floorArr.splice(0, 1);
...@@ -69,7 +74,7 @@ function move() { ...@@ -69,7 +74,7 @@ function move() {
} else if (floorArr[0] === 2) { } else if (floorArr[0] === 2) {
liftBox.style.marginTop = "408px"; liftBox.style.marginTop = "408px";
liftBox.style.transition = "5s"; liftBox.style.transition = "5s";
currentFloor = 2;
setTimeout(() => { setTimeout(() => {
if (floorArr.length !== 0) { if (floorArr.length !== 0) {
floorArr.splice(0, 1); floorArr.splice(0, 1);
...@@ -81,6 +86,7 @@ function move() { ...@@ -81,6 +86,7 @@ function move() {
} else if (floorArr[0] === 3) { } else if (floorArr[0] === 3) {
liftBox.style.marginTop = "272px"; liftBox.style.marginTop = "272px";
liftBox.style.transition = "5s"; liftBox.style.transition = "5s";
currentFloor = 3;
setTimeout(() => { setTimeout(() => {
if (floorArr.length !== 0) { if (floorArr.length !== 0) {
floorArr.splice(0, 1); floorArr.splice(0, 1);
...@@ -92,6 +98,7 @@ function move() { ...@@ -92,6 +98,7 @@ function move() {
} else if (floorArr[0] === 4) { } else if (floorArr[0] === 4) {
liftBox.style.marginTop = "136px"; liftBox.style.marginTop = "136px";
liftBox.style.transition = "5s"; liftBox.style.transition = "5s";
currentFloor = 4;
setTimeout(() => { setTimeout(() => {
if (floorArr.length !== 0) { if (floorArr.length !== 0) {
floorArr.splice(0, 1); floorArr.splice(0, 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment