Reset a count in a different function javascript (JS) and some Jquery

I have a quiz that allows to user to take the quiz 3 times and if they don't pass on the third time, they don't get a certificate at the end of the course.
The counts reset when the user passes the quiz.

 

//Counts the clicks

 let message = 0;
function showMessage(){
  message +=1
  if (message===1){
    alert("Sorry, you have failed. \nYou must score 80% or above to pass. \nPlease click reset button to try again. \nYou have two attempts left."); 
    }

    else if (message===2){
    alert("Sorry, you have failed.\nYou must score 80% or above to pass. \nPlease click reset button to try again.\nYou have one attempt left.");
}
 

  }
  else if (message===3) {
      alert("Sorry, you have failed.\nYou must score 80% or above to pass. \nYou did not pass you last attempt, you will not be eligible for a certificate. \nPlease click next button to continue course.");
      message = 0
    }
   
}
//resets messages if user passes quiz
function resetMessages() {
        message = 0;
    }

 

//Calling the reset in another function

 if (result.includes('quiz-passed')) {
                    
                    alert ("You have passed! \nPlease click the next button to continue with the course.");
                    resetMessages();
                }
                

            else {
                    showMessage();
                }

Blog Type: