MadLib Generator (Module #9 Mixed Messages)

PROJECT SUMMARY
For this project, I decided to create a MadLib generator! While most MadLibs require the user to supply their own nouns, adjectives, etc., I wanted this program to randomly select its own from a pre-defined list. The user can add their own or replace mine entirely. This creates tons of random funniness!

I had a lot of fun creating this program! My favorite part is creating the sentences used by the generator, even though I’m not very good at coming up with funny sentences. Please do us both justice and replace mine with your own :slight_smile:

GITHUB REPO

HOW LONG DID IT TAKE?
The project took around 3-4 days to complete, including documentation. I work two jobs, so the amount of time I had available was fairly sparse.

WHAT DID I LEARN?

Regular Expressions
To parse the sentences, this project makes use of regular expressions, which I’m not very adept at. So, I used https://regex101.com/ and toyed around with the documentation and eventually learned the regular expression to locate what I call “tags” (text between square brackets, such as [bookTitle])

For anybody wanting to know, the pattern is: /\[(.*?)\]/gi


Math.random()
The project also makes heavy use of JavaScript’s Math.random() to choose random nouns, adjectives, verbs, etc. as well as choose random sentences to present to the user.

case 'food':
  this._values.push(food[Math.floor(Math.random() * food.length)])
  break

JavaScript Classes
Lastly, I haven’t used JavaScript classes much before, so I decided to use a class-based approach for this project. I don’t believe the getters and setters are used in this project, but they are there and ready for anyone forking this experiment to use as they see fit.

HOW DID I DO?
Let me know how I did :slight_smile: Much can be improved in the code, I am sure. Maybe someday I can code along with someone and learn even more. Thanks for checking this out!