title: Alert and Prompt in JavaScript are always being executed before anything else
body: <p>Hello guys I am facing a weird problem while programming is JavaScript (No wonder! its JS). Well so the 
  problem is alert, confirm or prompt are always getting executed before anything else I mean even before the page is loading no matter where I write them.
  If I code like this:</p>
  
  <p>document.write("Hello World"); </p>
  
  <p>prompt("Enter your name: ");</p>
  
  <p>still the prompt() is executed before document.write().
  I know there is a way to control this by using function and calling it on button press. But can you guys suggest me any other simpler way to control this cuz I am really newbie to JS so.... </p>
  
  <p>THIS IS MY CODE:</p>
  
  <p><a href="https://i.stack.imgur.com/JChXk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JChXk.png" alt="enter image description here"></a></p>
  
  <p>Actually the task my teacher gave me is to:</p>
  
  <p>1) Create an array of color names</p>
  
  <p>2) Display it on HTML</p>
  
  <p>3) Take input of another color through prompt</p>
  
  <p>4) Add color from input at start of array</p>
  
  <p>5) Display the updated array on HTML again</p>
  
  <p><strong>Now what is happening is when I am opening my HTML file in which I linked this script immediately asks me for the input of color (prompt on line:4) even before the loading I mean without displaying the default array on HTML page. When I enter the color the page fully loads and shows me default array as well as updated array. But I don't want it to work like that I have to get input after displaying the default array.</strong></p>