-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainFile.js
51 lines (45 loc) · 2.22 KB
/
mainFile.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
40
41
42
43
44
45
46
47
48
49
50
51
// Create an array of objects
const messages = [
{
subject: "You",
adjectives: ["smart", "funny", "kind", "talented", "amazing"],
verbs: ["are", "can be", "will be", "should be", "must be"],
objects: ["do anything you set your mind to", "achieve great things", "make a difference in the world"],
adverbialPhrases: ["with ease", "with passion", "with dedication"],
},
{
subject: "The world",
adjectives: ["big", "beautiful", "complex", "fascinating", "mysterious"],
verbs: ["needs"],
objects: ["your intelligence", "your creativity", "your empathy", "your passion", "your dedication"],
adverbialPhrases: ["more than ever", "now more than ever"],
},
{
subject: "Happiness",
adjectives: ["true", "lasting", "genuine", "fulfilling", "deep"],
verbs: ["is found"],
objects: ["in helping others", "in pursuing your dreams", "in appreciating the simple things in life", "in being kind to yourself and others", "in finding your purpose"],
adverbialPhrases: ["when you least expect it"],
},
];
// Generate a random index into the array
const randomIndex = Math.floor(Math.random() * messages.length);
// Get the random message object
const randomMessage = messages[randomIndex];
// Randomly select a word from each list in the message object
const randomSubject = randomMessage.subject;
const randomAdjective = randomMessage.adjectives[Math.floor(Math.random() * randomMessage.adjectives.length)];
const randomVerbIndex = Math.floor(Math.random() * randomMessage.verbs.length);
const randomVerb = randomMessage.verbs[randomVerbIndex];
const randomObject = randomMessage.objects[Math.floor(Math.random() * randomMessage.objects.length)];
let randomAdverbialPhrase;
if (Array.isArray(randomMessage.adverbialPhrases)) {
const randomIndex = Math.floor(Math.random() * randomMessage.adverbialPhrases.length);
randomAdverbialPhrase = randomMessage.adverbialPhrases[randomIndex];
} else {
randomAdverbialPhrase = randomMessage.adverbialPhrases;
}
// Construct the random message
let message = randomSubject + " " + randomVerb + " " + randomAdjective + " and " + randomObject + " " + randomAdverbialPhrase + ".";
// Display the random message
console.log(message);