How to edit code for state-based user access restriction?

I’m trying to edit the code I found on https://community.shopify.com/c/shopify-design/site-access-add-age-verification-to-your-online-store/td-p/613515 so that I can also check their state. I’ve got the state box entered, and it will pop up an alert, but I can’t figure out how to make it so that only certain states are allowed in. We can only ship to certain states, so we want to make that known up front.

This is what I have so far for the function:

function stateCheck() {
  var legal_state = {{ enter_state }};  // sets legal states
  var state = parseInt(document.getElementById('bystate').value);
  if ((bystate != legal_state)) {
      {alert("this state is not legal. we can not sell to you.")}
  
  } else {
  var state = parseInt(document.getElementById('bystate').value);
  if ((bystate = legal_state)) {
    location.reload();
  }
  }

  }

Above that I reference the values of the states that are legal. I only entered for for testing.

{% assign legal_state = 50 %}

The option value is listed in a drop down in a select area.

Any suggestions?