Taking one of the suggestions from the A2Z site, I decided to build a madlib generator. I wanted to use classic literature passages, but was inspired by this article to use just the first passage to make the madlib size manageable.
- User is given a list of words to add in
- Validate that every text box is filled in
- User hits Enter button
- Passage generates with added words.
- User hits back button to reset and replay as much as they like
I hardcoded a few opening passages: Pride and Prejudice, Moby Dick, The Raven, and Tale of Two Cities were the test passages. In the future I'd like to pull in more sources, but that may require a database or some means to pull it out of my JS file.
There are two remaining tasks:
- Bug - Sometimes the app won't accept certain words and will show the user an error message that the word isn't the right part of speech. I didn't realize that when I asked for the part of speech of the word being replaced that I would be getting an array instead of a single value. I'll need to alter my code to account for this, but this leads to the issue that there's no good way of knowing which part of speech the word is using in the context of the main text.
- Formatting the text when I put it back together - I tokenized the passages to get the individual words stored, but I need to find a way to piece them back together into sentences while retaining the punctuation. I also would like to format the words that were inserted so that they have a different visual treatment and so the user can hover on them and see what the original word was.
This was a lot of fun to do! I ran out of time, but I'm beginning to think about rearchitecting the app to build better data structures for storing my information and optimizing the functions I built so that my primary word replace algorithm can be simplified (if possible).