Javascript ,help for Random qoute machine project

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 — >
Thanks .!

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() {

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.

1 Like

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

1 Like

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