onClick event on Random quote machine

Building Random Quote machine, I am trying to make button generate random number whenever I click on it. But, the number generated only when the page loaded not when the button clicked. Is there anything I am missing? thank you

https://codepen.io/Amasian/pen/QmBgNz

test this?

Couple of issues with your code:

#1) You have an onclick event handler on your button which attempts to run a function called onload. The problem is, you have not defined a function named onload anywhere in your code.

#2) document.createElement(“P”).createTextNode(“First”) is not valid syntax. If you really want to randomly create a p element and put a specific text node in it, then you could write the code as:

var pElem = document.createElement("P");
var textElem;
switch (randomNumGenerator()) {
  case 1:
    textElem = document.createTextNode("First");
    break;
  case 2:
    textElem = document.createTextNode("Second");
    break;
  case 3:
    textElem = document.createTextNode("Third");
    break;
  case 4:
    textElem = document.createTextNode("Fourth");
    break;
}
pElem.appendChild(textElem);
document.body.appendChild(pElem);

or a more DRY (Do Not Repeat Yourself) version:

var pElem = document.createElement("P");
var text;
switch (randomNumGenerator()) {
  case 1:
    text = "First";
    break;
  case 2:
    text = "Second";
    break;
  case 3:
    text = "Third";
    break;
  case 4:
    text = "Fourth";
    break;
}
pElem.appendChild(document.createTextNode(text));
document.body.appendChild(pElem);

I would recommend writing your button.onclick function in your JS file. Right now there is no code linking the button in your html to the “brain” of the app, your JS file.