Help with Random Quotes Machine needed - JS code not working

Hi,
Sorry if I ask a dumb question, I am sure this was asked before. Why my JS code doesn’t work? I am sure I did something wrong, but what? Even if the code is wrong shouldn’t JS do something, anything?

In your newQuote function you are selecting the element with the ID New Quote, which in your HTML is your button, rather than an output DIV.

You also need an onclick or eventlistener to call your New Quote function, when the button is being clicked.

Your first quote is not being randomly generated either.

e. g.

getElementById(“buttonid”).addEventListener(“click”, newQuote())

1 Like

There are a few things that are incorrect/missing:

  • “New Quote” is not a valid id (see link below)
  • Nothing happens when you click the new quote button because you don’t have an event listener.
  • You are not selecting output div

EDIT: Basically what @nextstoplondon said + invalid ID

1 Like

newQuote() should be newQuote because you are passing the function as an argument rather than the result of the function.

1 Like

Thank you, both of you, I am trying to fix the code now.

It worked, thank you very much again. Now I can focus on making it pretty. :)) Any suggestions you may have are welcomed.