Javascript ,help for Random qoute machine project

Javascript ,help for Random qoute machine project
0

#1

Hello coders :)) ,im currently on project “Build a Random Quote Machine” and im little bit stuck .
I have found a function that typewrites the quote ,but if you click the button for the new quote ,when the first quote typewriting function hasn’t finished it bugs out ,what should i do to prevent this ?
i can’t figure it out ;/
Project link — > http://codepen.io/leprikonas/pen/eBROYq
Thanks .!


#2

When you click on the button you should reset the timeout function with clearTimeout(), making sure no more than one instance is running. setTimeout() returns with an ID you can use in if you want to reset it later. (Watch out for variable scoping :slight_smile: )

An example from MDN:

var timeoutID;

function delayedAlert() {
  timeoutID = setTimeout(slowAlert, 2000);
}

function slowAlert() {
  alert("That was really slow!");
}

function clearAlert() {
  clearTimeout(timeoutID);
}

And an extra tip: Set your background’s size to cover by adding background-size: cover; to make it look better on different screen sizes.


#3

I think zsoitime gave the best solution.

An alternative design would be disabling the button until the typewriter is finished. You would use jquery to disable the button on click and check for n = text.length - 1 to re-enable it.

Just depends on how you want to app to act


#4

thanks cjsheets and zsoltime ,gona try now :slight_smile: have a good day lads