JSFiddle - React, Tailwind, and code Playground
by jesus_tesh
HTML
<h1>Your program produced:</h1>
<p id="fill"></p>
<h1>Our program produced:</h1>
<p>Story the happened of a. Port above channel. I tuned was and the. The I. Of burn as such more bit more various more from. Tuned sky. Generally was. Above color more less was. It. Each people. Bit dead pleasure this story a generally the bit bit and. To as pleasure to port the from and and each happens. Various different people. Sky. Each story. Happens and I happens or each. Each the a from it had burn channel the. From all this bit. Channel. And to by. I happened. Port. Happened. Pleasure. Sky to. Pleasure time cases was. Television it was a. Color. Sky. A dead the from. Had above. It as. It the to the a pleasure channel generally burn of and the various to burn was happened sky people. Pleasure was I. It bit. Happened I sky was it in happened all as. Above. This all happens story. Sky the color was above cases people the above or each this to the the by to various was or the was people. Happened. From. In story a happened to. Happened sky it people. To bit all generally cases. To. Happens</p>
JavaScript
/* Lorem Ipsum Generator
Lorem Ipsum filler text is often used to mock how a page might look with real-looking text.
Your task is to create a program that generates filler text like you can see that our program
produced by changing the function "generateIpsum()" below.
The source for the filler words must come from the variable "words" to produce about 1000
characters of output.
The time limit for this task is 20 minutes. If you run out of time, it is sufficient to
explain how your solution is better or worse than the output of our program and how you
would improve it if you had more time.
Send the contents of this pane and the contents of the Result pane as text files when done.
*/
var words = "The sky above the port was the color of television, tuned to a dead channel. All this happened, more or less. I had the story, bit by bit, from various people, and, as generally happens in such cases, each time it was a different story. It was a pleasure to burn.";
function generateIpsum() {
var maxLength = 1000;
var minWords = 2;
var maxWords = 10;
var cleanedWords = words.replace(/\./g, '').replace(/,/g, '').toLowerCase();
var splitWords = cleanedWords.split(' ');
var wordCount = splitWords.length;
var output = "";
while (output.length < maxLength) {
if (output.length > 0) {
output += " ";
}
var sentenceLength = getRandomInt(minWords, maxWords);
for (var i = 0; i < sentenceLength; i++) {
if (i > 0) {
output += " "
}
var idx = getRandomInt(1, wordCount);
if (i === 0) {
var word = splitWords[idx];
output += word.charAt(0).toUpperCase() +
word.slice(1);
} else {
output += splitWords[idx];
}
}
output += "."
}
console.log("output",...