I’m trying to create a random quote generator. I have created a function called timer that runs another function pickQuote every 400ms but at the moment this doesn’t seem to work. in pickQuote I run a function randomNumberGen that creates a random number. My problem in the randomNumberGen is that I want to have an if or if..else in place that checks whether or not the new random number is different from the current quotes[randomNumber] but i’m unsure how to do this.
Can anyone provide me with some insight on how I can achieve this?
My current effort can be viewed here: http://jsbin.com/aqinud/12/edit
indexis not defined outside$.each. Variables in functions are not accessible outside it if you usevar.What I recommend is altering the function as follows:
So, first create a random number and only if it’s different from
randomNumber, update it with the newly created one. Otherwise, try again.Also,
setTimeoutrequires a function, so don’t invoke it yet:http://jsbin.com/aqinud/13/edit