-1

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>
Daniel Beck
  • 20,653
  • 5
  • 38
  • 53
Max
  • 23
  • 4

1 Answers1

1

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

Minimal example;

let gamerName;
$(document).ready(function(){
    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>
0stone0
  • 34,288
  • 4
  • 39
  • 64
  • This worked, but we were told to assign the global variable outside of doc ready. Is there a way to do that? – Max Feb 17 '21 at 17:08
  • Of course, please take a look at my edit. Otherwise, consider reading about [defining global variables](https://stackoverflow.com/questions/5786851/define-a-global-variable-in-a-javascript-function) – 0stone0 Feb 17 '21 at 17:14