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,42 +10,47 @@ let btn0 = document.getElementById("btn0"), ...@@ -10,42 +10,47 @@ 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++) {
case 0: if (floorArr[i] !== currentFloor) {
btn0.style.backgroundColor = "red"; switch (floorArr[i]) {
break; case 0:
case 1: btn0.style.backgroundColor = "red";
btn1.style.backgroundColor = "red"; break;
break; case 1:
case 2: btn1.style.backgroundColor = "red";
btn2.style.backgroundColor = "red"; break;
console.log("first"); case 2:
break; btn2.style.backgroundColor = "red";
case 3: console.log("first");
btn3.style.backgroundColor = "red"; break;
break; case 3:
case 4: btn3.style.backgroundColor = "red";
btn4.style.backgroundColor = "red"; break;
break; case 4:
default: btn4.style.backgroundColor = "red";
break; break;
default:
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