JSFiddle - React, Tailwind, and code Playground
by whelkaholism
HTML
<div id="o">
</div>
JavaScript
var cFront = {};
cFront.SenGen = function()
{
var _this = this;
this.grammar = [
'I @verb the @noun',
'I @verb the @adjective @noun',
'I @adverb @verb the @noun',
'I @adverb @verb the @adjective @noun',
'@adverb, I @verb the @noun',
'@adverb, I @verb the @adjective @noun'
];
this.linkages = [
'; ',
', ',
' and '
];
this.generateSingle = function(noterminator)
{
var s = _this.generate();
return s[0].toUpperCase() + s.substring(1) + (!noterminator && '.');
};
this.generateRunOn = function(num, noterminator)
{
var a = [];
for(var i = 0; i < num; i++)
{
var s = _this.generate();
var link = i < num - 1 ? _this.linkages[Math.floor(Math.random() * _this.linkages.length)] : '';
a.push(s + link);
}
var s = a.join('');
return s[0].toUpperCase() + s.substring(1) + (!noterminator && '.');
};
this.generate = function()
{
var isen = Math.floor(Math.random() * _this.grammar.length);
return this.populateSentence(_this.grammar[isen]);
};
this.populateSentence = function(sentence)
{
if(!sentence)
return;
return sentence.replace(/@([a-z0-9]+)/g,
function(match, p1)
{
var word = null;
var ivoc;
while(word == null)
{
ivoc = Math.floor(Math.random() * _this.vocab.length);
word = _this.vocab[ivoc][p1];
}
return word;
}
);
};
//
this.vocab = [
{
verb: 'accept',
noun: 'acceptance',
adjective: 'acceptable',
adverb: null
},
{
verb: 'achieve',
noun: 'achievement',
adjective: 'achievable',
adverb: null
},
{
verb: 'act',
noun: 'action',
adjective: 'active',
adverb: 'actively'
},
{
verb: 'act',
noun: 'activity',
adjective: 'active',
adverb: 'actively'
},
{
verb: 'act',
noun: 'activeness',
adjective: 'active',
adverb:...