Why doesn’t my loop break when parcels.lenght === 0 ?
function completeRoute(start) {
let at = start;
pickUpParcels(at);
for (let turns = 0; ; turns++) {
console.log("turns = " + turns);
console.log("pickedUp length for loop " + pickedUp.lenght);
console.log("parcels length for loop " + parcels.length);
if (parcels.lenght === 0) {
console.log(`Delivered in ${turns} turns`);
break;
}
console.log("dest lenght = " + destination.length);
if (destination.length === 0) getDestination();
//console.log("destination " + destination);
getRoute(at, destination[0]);
console.log("route " + destination[0]);
move(at, destination[0]);
at = destination[0]
destination.shift();
}
}
completeRoute("Post Office");
As you can see parcels.lenght hits zero but the loop continues.
The full code on GitHub.
Secondary question, why is pickedUp.length undefined within function completeRoute when it is not undefined elsewhere in the code?
