-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
39 lines (30 loc) · 1.11 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const words = [
"lorem", "ipsum", "dolor", "sit", "amet", "consectetur",
"adipiscing", "elit", "sed", "do", "eiusmod", "tempor",
"incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua"
];
function generateSentence() {
const sentenceLength = Math.floor(Math.random() * (15 - 4)) + 4;
let sentence = [];
for (let i = 0; i < sentenceLength; i++) {
const randomIndex = Math.floor(Math.random() * words.length);
sentence.push(words[randomIndex]);
}
return sentence[0].charAt(0).toUpperCase() + sentence.slice(1).join(" ") + ".";
}
function generateParagraph() {
const paragraphLength = Math.floor(Math.random() * (6 - 3)) + 3;
let paragraph = [];
for (let i = 0; i < paragraphLength; i++) {
paragraph.push(generateSentence());
}
return paragraph.join(" ");
}
function generateLoremIpsum() {
const numParagraphs = document.getElementById("paragraphs").value;
let output = "";
for (let i = 0; i < numParagraphs; i++) {
output += `<p>${generateParagraph()}</p>`;
}
document.getElementById("output").innerHTML = output;
}