How to calculate duration & distance with setAvoid() : I receive the same duration & distance whether or not I am expecting to avoid highways or tolls

I suspect the issue is either in my order of operations, or the way I am calculating distance & duration

I have tried setting up setAvoid in two different ways (see code), as well as changed my if statements to accommodate what the HTML form (check box) might return.

I have also tried switching the if statement to "return formObject.avoid1"
this showed me that the if statement is functioning properly - so either the .setAvoid is not working the way I have written it, or the distance & duration calculations are not considering the setAvoid

      if (formObject.avoid1 == "TRUE"){
        mapObj.setAvoid(Maps.DirectionFinder.Avoid.HIGHWAYS);
        }
        
      if (formObject.avoid2 == "yes"){
        mapObj.setAvoid("tolls");
        }
               
      var directions = mapObj.getDirections();
      var bestRoute = directions["routes"][0];
      var numLegs = bestRoute["legs"].length;
    
      for (var c=0; c<numLegs; ++c){
        var legNum = directions["routes"][0]["legs"][c];
        var legDistance = legNum["distance"]["value"];
        var legDuration = legNum["duration"]["value"];
        totalDistance += legDistance;
        totalDuration += legDuration;
        }

If we are in fact avoiding highways, I expect the duration to increase, but I get the same duration whether or not we avoid highways