How do you call a prompt on page load with jquery?

I cant seem to figure it out. This is what I have so far:

 <head>
  
  <script src="jquery-3.5.1.min.js"></script>
    var gamerName
    
    <script>
      $(document).ready(function(){
        gamerName = prompt("Please enter your name."," ");
    });
      
</script>  
    
    
  </head>

1 thought on “How do you call a prompt on page load with jquery?”

  1. Keep the var assignment inside the script tag! Otherwise it will be parsed as HTML.

    Minimal example;

    $(document).ready(function(){
        const gamerName = prompt("Please enter your name."," ");
        console.log(gamerName);
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    Reply

Leave a Comment