JSFiddle - React, Tailwind, and code Playground
JavaScript
function titleCase(str){
str = str.toLowerCase().replace(/\b[a-z]/g, function(letter) {
return letter.toUpperCase();
});
return str;}
var xhr = new XMLHttpRequest();
xhr.open("GET", "/api/dictionary", true);
xhr.send(null);
xhr = JSON.parse(xhr.response);
var nouns = xhr.nouns,
adjectives = xhr.adjectives;
adjectives = adjectives.map(titleCase);
nouns = nouns.map(titleCase);
function randomizer(){
var randNouns = Math.floor(Math.random() * nouns.length),
randAdjectives = Math.floor(Math.random() * adjectives.length),
checker = [],
name;
name = nouns[randNouns]+adjectives[randAdjectives];
while(checker.indexOf(name)!=-1){
randNouns = Math.floor(Math.random() * nouns.length);
randAdjectives = Math.floor(Math.random() * adjectives.length);
name = nouns[randNouns]+adjectives[randAdjectives];
}
if ( checker.length<10){checker.push(name);}
else {checker.shift(); checker.push(name);}
console.log(name);
}