-2

I am creating website that contains banner div at top and which has background image also now i have to put text on top of it like this

         welcome know my facilities
      1.xxxxxxxxxx          4.xxxxxxxxxxx
      2.xxxxxxxxxx          5.xxxxxxxxxxx
      3.xxxxxxxxxx          6.xxxxxxxxxx

how i display 1,2,3,4,5,6 randomly on banner using javascript.

  • Please provide some code snippets of what you have tried, so that other can easily understand the problem. – tejashsoni111 May 31 '14 at 08:33
  • you haven't provided anything showing that you even tried something... give it a go using loads of documentation on the net and let us know if you're stuck... – benomatis May 31 '14 at 08:34
  • What do you mean randomly? Do they have to be in a random order? Or is the text randomly selected from a set of say 20 options? – Husman May 31 '14 at 08:35

1 Answers1

0
  1. Create an array with an entry for each of the six options. Those will be entries 0 through 5 inclusive. Each entry has the HTML you want displayed for that entry.

  2. Use x = Math.floor(Math.random() * theArray.length); to pick a random whole number between 0 and 5, inclusive.

  3. Use theArray[x] to retrieve the content you want to display.

  4. Use document.getElementById or document.querySelector to get a reference to the DOM element for the banner.

  5. Use its innerHTML property to put the content in it.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875