keytone Posted January 12, 2015 Share Posted January 12, 2015 Hello again everyone! Yes indeed, I come groveling back with another question. I'm trying to let the user click to go through an array of quotations. It works fine, but I can only get it to work if I use Math.round and Math,random I don't know how to use anything but random I want to just go through the array in order,then start over. Maybe I need to do do something the variable num I don't know and I've got myself so confused that I'm tearing my hair out, and if you see my picture you can see I don't have much to spare! The page: http://jdsplace.us/generator/funnyquotes.html Here's the code: <html> <head> <title> A Few Funny Quotes </title> <HEAD> <style> .row { padding-left:10px;background-color:white; font-family: verdana, san-serif;font-size: 16px } </style> <script type="text/javascript"> var arr= new Array(); arr.push("MISUNDERESTIMATED---They misunderestimated me.---Bentonville, Arkansas, on November 6, 2000;"); arr.push("And they have no disregard for human life.----George W. Bush-- on the brutality of Afghan fighters"); arr.push("Throughout our history, these immigrants have helped transform 13 small colonies into a great and growing nation of more than 300 people.-George Bush--Charlottesville, Virginia, July 4, 2008"); arr.push("VICTORY and SUCCESS---'So long as I'm the president, my measure of success is victory, and success.'--On Iraq, in Washington, D.C., on April 17, 2008"); arr.push("------------I Wish [the Enemy] All the Very Best------------'I'm telling you there's an enemy that would like to attack America, Americans, again. There just is. That's the reality of the world. And I wish him all the very best.'-Washington,D.C., on January 12, 2009"); arr.push(" 'I'll be long gone before some smart person ever figures out what happened inside this Oval Office.'-- Washington, D.C., on May 12, 2008"); arr.push(" 'Awesome Speech! Thank you, your Holiness. Awesome speech!' --To Pope Benedict, in Washington, D.C., on April 15, 2008"); arr.push("------------------Do You Ever Hear Voices?----------------- 'People say, well, do you ever hear any other voices other than, like, a few people? Uh well...Of course I do.'-----------In Washington, D.C., on December 18, 2008"); arr.push("--------------------Abducted in the Oval Office--------------------'I remember meeting a mother of a child who was abducted by the North Koreans right here in the Oval Office.'--In Washington, D.C., on June 26, 2008"); arr.push("************* $4-a-Gallon Gas? ! **************** 'Wait a minute! What did you just say?-- You're predicting $4-a-gallon gas? ... That's interesting. I hadn't heard that.---In Washington, D.C., on February 28, 2008"); arr.push("******** It's Going to Take a While to Unthaw******** 'This thaw took a while to thaw, it's going to take a while to unthaw.'--On liquidity in the markets, Alexandria, Louisiana, on October 20, 2008"); arr.push("*******I've Abandoned Free Market Principles******** 'I've abandoned free market principles to save the free market system.'--In Washington, D.C., on December 16, 2008"); arr.push("---I Didn't Want to be the President During a Depression---************************************************ 'So I analyzed that and decided I didn't want to be the president during a depression greater than the Great Depression, or the beginning of a depression greater than the Great Depression.'--In Washington D.C., on December 18, 2008"); arr.push("Dont stay in bed, unless you can make money in bed.- George Burns 1896-1996"); arr.push("Nothing in the world is more dangerous than sincere ignorance and conscientious stupidity.- Martin Luther King Jr. 1929-1968"); arr.push("Not a shred of evidence exists in favor of the idea that life is serious."); arr.push("Dont be so humble - you are not that great.- Golda Meir 1898-1978 to a visiting diplomat"); arr.push("Political correctness is tyranny with manners.- Charlton Heston 1924-"); function rotate() { var num= Math.round(Math.random()*18); add(num); } function add(i) { var chi = document.createTextNode(arr); var tab1 = document.getElementById("add1"); while(tab1.hasChildNodes()) { tab1.removeChild(tab1.firstChild); } tab1.appendChild(chi); } </script> </HEAD> <BODY background="/background_images/b2.gif"> <a href="/new/interesting/interesting1.html"><img src="/gif/backmarble.gif" border="none"></a> <table align=center style="background-color:#cc9900";> <tr><td background-color:#cc9900 align=center width=400 style="font-family:Times New Roman;"><b>Bush's Best !</td></tr> <tr><td id=add1 class=row width=500 align=center>click Next for a Famous Quote</td></tr> <tr><td align=center><input type=button color="blue" value="Next Quote" border=0 onclick="rotate()"></td></tr> </table> </center> </body> </html> Would one of you gurus tell me what I'm doing wrong? I appreciate you very much. keytone Link to comment Share on other sites More sharing options...
Ingolme Posted January 12, 2015 Share Posted January 12, 2015 Make a global variable, let's say index. var index = 0; In your rotate function, show the element at index index, then add 1 to index. To ensure that the variable index is within the bounds of the array we can use the % (remainder of division) operator. function rotate() { // This is your other function which doesn't need to be changed add(index); // Add 1 to index index++; // Same as index = index % arr.length; index %= arr.length;} Link to comment Share on other sites More sharing options...
keytone Posted January 12, 2015 Author Share Posted January 12, 2015 Thank you very, very much! You truly are the Wizard of foxes! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now