title: Javascript function to display a number and then delete it won't work
body: <p>I am attempting to make a simple n-back game (memory game that requires players to watch a string of numbers pop up and then go away and match current numbers with previous numbers a certain number of steps back). I am trying to create a simple function that will generate a random number, add it to a string, display the string, then stop displaying it and reset the string by removing the number from it. After I am able to create this function and have it work, I want to loop it with a for-loop. However, I have spend over an hour just trying to get this function to work correctly to no avail. See code below: </p>
  
  <pre><code>var htmlElement = "#numbers-display";
  
  
  
     /*
      This function generates a random number, adds it to a 
     string, then displays the string in an html element, then turns off the 
     display after a delay, then deletes the number from the string.
     */
  
  function displayNumber() {
    var randomNumber = Math.floor(Math.random()*10);
    var displayNumber = "";
    displayNumber+=randomNumber;
    $("#numbers-display").html(displayNumber);
    window.setTimeout(dump(htmlElement), 2500);
    displayNumber.substr(1);
  };
  
  //This function empties the html contents of an element.
  function dump(element) {
    $(element).empty();
  };
  </code></pre>
  
  <p>Part of my problem is that I can't seem to ever get setTimeout() to work correctly. I really don't know why. For this game I want to do a lot of things after a short delay, but setTimeout never works for me. Anyway, any help with getting this up and running would  be greatly appreciated, since I can't even begin to start building the other parts of this game if I can't even get a string of random numbers to display one after the other. Keep in mind I am a total newbie who still has difficulty accomplishing the most basic things.</p>