Hiya, this is my first post - I'll try to make sure I'm doing things correct!
I'm trying to create a random text generator, I've got the random text generating part down, but after I click the button and get the random text, I lose my button so I can't continue to generate random text. Help?
Code:
<!DOCTYPE html>
<html>
<body>
<p id="generator">Generate a random fact</p>
<button onclick="myFunction()">Try it</button>
<script>
Array.prototype.myUcase=function()
{
for (i=0;i<this.length;i++)
{
this[i]=this[i].toUpperCase();
}
}
function myFunction()
{
var r_text = new Array ();
r_text[0] = "Give a homeless man a gift card";
r_text[1] = "Hold the door for a stranger";
r_text[2] = "Pay for a stranger's lunch";
r_text[3] = "Compliment the next person you see";
r_text[4] = "Take your neighbor's dog for a walk";
r_text[5] = "Send greeting cards to random addresses";
r_text[6] = "Load a vending machine with money";
var i = Math.floor(7*Math.random())
document.write(r_text[i]);
}
</script>
</body>
</html>
<script language="JavaScript">
<!--
//-->
</script>
Here is a snippit if that doesn't work:
http://snipt.org/vfAe1
Also, any resources or directions you can provide would be great, my knowledge is good in some areas, and I'm a complete idiot in other areas!