DEV Community

Cover image for How to make a Domain Generator
Luis Linares
Luis Linares

Posted on

How to make a Domain Generator

This is a project for my Bootcamp in 4GeeksAcademyVe

Image description

📝 Instructions
Create a script that generates all the possible domain name combinations from a list of pronouns, adjectives, and nouns, for example:

1  let pronoun = ['the','our'];
2  let adj = ['great', 'big' ];
3  let noun = ['jogger','racoon'];
Enter fullscreen mode Exit fullscreen mode

Should generate something like:

1thegreatjogger.com
2thegreatracoon.com
3ourgreatjogger.com
4ourgreatracoon.com
5thebigjogger.com
6thebigracoon.com
7ourbigjogger.com
8ourbigracoon.com
Enter fullscreen mode Exit fullscreen mode

💡 Hint
You’ll need to use nested for loops in order to mix the different values together.

Your tools: For loop, string concatenation.

There are two ways of doing this.

let pronouns = ["the", "our"];
     let adjs = ["great", "big"];
     let nouns = ["jogger", "racoon"];
     let domains = [".com", ".org", ".us", ".ve"];
     for (let pronoun of pronouns) {
       for (let adj of adjs) {
         for (let noun of nouns) {
           for (let domain of domains) {
             console.log(`${pronoun}${adj}${noun}${domain}`);
           }
         }
       }
     }
   };
Enter fullscreen mode Exit fullscreen mode

And this is a For loop.

  window.onload = function() {
     let dominio = [".com", ".org", ".net", ".io"];
     let pronoun = ["the", "our"];
     let adj = ["great", "big"];
     let noun = ["jogger", "racoon"];

     for (let i = 0; i < pronoun.length; i++) {
       for (let j = 0; j < adj.length; j++) {
         for (let p = 0; p < noun.length; p++) {
           for (let r = 0; r < dominio.length; r++) {
             console.log(`${pronoun[i]}${adj[j]}${noun[p]}${dominio[r]}`);
           }
         }
       }
     }
   };
Enter fullscreen mode Exit fullscreen mode

In the first example, I had some help, but the second was the initial idea.

Do you know another way of doing this? Let me know.

Top comments (0)