Why doesn't my for loop break?

Why doesn’t my loop break when parcels.lenght === 0 ?

function completeRoute(start) { 
  let at = start;
  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`);
    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]
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?

You misspelled length in quite a few places

1 Like

Thanks, embarrassed, I thought emmet in VS Code had my back on that. But I must have fully typed it out. Good news I guess is the code logic was right. Have to be more careful in the future.