Skip to content

Instantly share code, notes, and snippets.

@ryumada
Created January 24, 2021 02:26
Show Gist options
  • Save ryumada/275a40e3fde66a36f1ee169c5028638a to your computer and use it in GitHub Desktop.
Save ryumada/275a40e3fde66a36f1ee169c5028638a to your computer and use it in GitHub Desktop.
Generate any title words with javascript
// generates random words
function createRandomWord(length) {
var consonants = 'bcdfghjlmnpqrstv',
vowels = 'aeiou',
rand = function(limit) {
return Math.floor(Math.random()*limit);
},
i, word='', length = parseInt(length,10),
consonants = consonants.split(''),
vowels = vowels.split('');
for (i=0;i<length/2;i++) {
var randConsonant = consonants[rand(consonants.length)],
randVowel = vowels[rand(vowels.length)];
word += (i===0) ? randConsonant.toUpperCase() : randConsonant;
word += i*2<length-1 ? randVowel : '';
}
return word;
}
var words = [];
for(x = 0; x < 3; x++){
words[x] = createRandomWord(5) // generate random word with length of word is 5
}
return words.join(' '); // join the words and separated by space
// referenced: https://jsfiddle.net/amando96/XjUJM/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment