JSFiddle - React, Tailwind, and code Playground
JavaScript
(function(count) {
var words = {
uarticle: ["The", "A", "One", "Some", "Any"],
noun: ["boy", "girl", "dog", "town", "car"],
verb: ["drove", "jumped", "ran", "walked", "skipped"],
larticle: ["the", "a", "one", "some", "any"],
preposition: ["to", "from", "over", "under", "on"]
};
// how it's structured (object keys will be used)
var sentence = ["uarticle","noun", "verb", "preposition", "larticle", "noun"];
// return a random array
var arrayRandom = function(myarray) {
return myarray[Math.floor ( Math.random() * myarray.length)];
};
// a temp array to store the selected random words.
var readySentence = [];
// loop it
while(count--) {
readySentence.length = 0; // empty the array on each loop
for (var ii = 0; ii < sentence.length; ++ii) {
readySentence.push(arrayRandom(words[sentence[ii]]));
};
document.writeln(readySentence.join(" ") +"<br/>");
}
})(20);