I have a bit of javascript and jQuery where I am using jQuery .each to loop through a set of text area boxes as part of a light spellcheck routine. I am also using jQuery addClass to change the border of the text areas if a spelling criteria is not reached. The spell checking and add class portion of the code work fine. Where I am stuck is in returning an error indicator that will either flag to remain on the page because of errors or carry on to the next page.
Code is below:
function executeFormCheckSubmit() {
  function getSpellCount(essayContent) {
    return new Promise((resolve, reject) => {
      jQuery(function(\$) {
        var values = {
          'str': essayContent
        };\
        $.ajax({
          type: "POST",
          url: "/path/to/scripts/ajax/spellcheckEssay.php",
          data: values,
          success: resolve,
          error: reject,
        })
      });
    })
  }
  function checkTextArea() {
    let elementID = "";
    let errorFlag = false;
    let textAreaCheck = \$("textarea").each(function(elementID, errorFlag) {
      let textbox = this.value;
      let percentage = getSpellCount(textbox);
      elementID = this.id;
      percentage.then(function(result) {
        let grade = result.percentage;
        if (grade < 80) {
          errorFlag = true;\
          $("#" + elementID).addClass("error");
        }
      }).catch(function(error) {
        console.log('Failed', error);
      });
    });
    return errorFlag;
  }
  let isError = checkTextArea();
  if (isError === true) {
    //alert("The text does not meet our minimum requirements.");
    console.log("isError is true.");
    return false;
  } else {
    console.log("isError is false.");
    //document.course_finger.submit();
  }
} 
    