-5

I am making a program that when a button is clicked it makes text appear randomly from an array (i have this part done). What I need help with is making the button able to be pressed over and over again and display something else every time.

input type="button" value="Maths" 
onClick = "document.getElementById('4').style.display='block';">
div id="4" style="display:none;"

script language="Javascript"
sent = new Array (6);
sent [0] = "Don't cry because it's over. Smile because it happened. -Dr.Seuss";
sent [1] = "So many books, so little time. -Frank Zappa";
sent [2] = "In three words I can sum up everything I've learned about life: it goes on. -Robert Frost";
sent [3] = "If you tell the truth, you don't have to remember anything. -Mark Twain";
sent [4] = "To live is the rarest thing in the world. Most people exist, that is all. -Oscar Wilde";
sent [5] = "To be yourself in a world that is constantly trying to make you something else is the greatest accomplishment. - Ralph Waldo Emerson";
x=Math.floor(Math.random()*6);  

    document.write(sent[x])
/script/div
  • 2
    Why aren't you using actual HTML, and using `document.write()`? – David says reinstate Monica May 12 '14 at 23:53
  • i dont know what you mean this is what my teacher tought. And i did use document.write() – user3630455 May 12 '14 at 23:56
  • 1
    What's your question? What problem have you encountered? – Drazen Bjelovuk May 12 '14 at 23:57
  • I mean: `input type="button" value="Maths" ` should (probably) be well-formed HTML: `` and yes, you're using `document.write()`, but you shouldn't be (see: http://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice). – David says reinstate Monica May 12 '14 at 23:58
  • i was not sure how to do that in stackoverflow it was not accepting it. – user3630455 May 12 '14 at 23:59
  • 1
    This isn't a website for getting people to just do your homework for you. Do some research (there's a plethora of resources on this stuff) and come back with a specific question or problem you've encountered. – Drazen Bjelovuk May 13 '14 at 00:07
  • Josh Bjelovuk, I have been working on my assignment for hours. I have done research to the extent of my understanding at my current stage. I am at the very beginning in learning JavaScript I am doing my best at learning the functions and code I have never previously coded before. So I would very much appreciate it if you back up. – user3630455 May 13 '14 at 00:14
  • "[Stack Overflow is for professional and enthusiast programmers](http://stackoverflow.com/help/on-topic)," it's not a place for beginner questions or tutorials. To receive our help you should, if not *must*, be able to demonstrate an understanding of the problem you're asking. Being new to Stack Overflow is fine, being new to programming may make this a difficult site from which to learn. – David says reinstate Monica May 13 '14 at 07:17

2 Answers2

0

You should place this in a loop. This will make the code persistent.

while (condition) {
code block to be executed
}
Torkoal
  • 409
  • 4
  • 17
0

Remove shown elements from the array

sent.splice(x,1);
MikeVelazco
  • 865
  • 1
  • 11
  • 26
  • This removes the element(s) from the "sent" array with the index "x". The second argument is the number of elements to remove from the index (the first argument). [check this](http://www.w3schools.com/jsref/jsref_splice.asp) – MikeVelazco May 13 '14 at 21:38