I'm trying to create a random name generator. How can I choose how many strings to generate without having to copy and paste so many duplicates of code? Is there a way to have an input box where I can type a number and it will generate that amount?
function generator() {
    var planets = ["mercury","venus","earth","mars","jupiter","saturn","uranus","neptune","pluto"];
    
    var planets = planets[Math.floor(Math.random() * planets.length)] + " " 
    + planets[Math.floor(Math.random() * planets.length)] + " "
    + planets[Math.floor(Math.random() * planets.length)] + " "
    + planets[Math.floor(Math.random() * planets.length)] + " "
    + planets[Math.floor(Math.random() * planets.length)] + " "
    + planets[Math.floor(Math.random() * planets.length)] + " "
    + planets[Math.floor(Math.random() * planets.length)] + " "
    + planets[Math.floor(Math.random() * planets.length)] + " "
    + planets[Math.floor(Math.random() * planets.length)] + " "
    + planets[Math.floor(Math.random() * planets.length)] + " "
    ;
    
    if (document.getElementById("planets")) {
    document.getElementById("placeholder").removeChild(document.getElementById("planets"));
    }
    
    var element = document.createElement("div");
    element.setAttribute("id", "planets");
    element.appendChild(document.createTextNode(planets));
    document.getElementById("placeholder").appendChild(element);
    }   
 
     
    