Mixed Messages - Fake Fact Generator

Heyo all o/
Just finished my Mixed Messages portfolio project.

The Goal

I decided to create a fake fact generator.

  1. Randomly select a sentence structure from a predefined array.
  2. Replace keywords in the sentance structure with a randomly selected word, from the category represented by said keyword. (Nouns, Verbs, Adverbs etc.)
  3. Log the sentence to the terminal with a randomly selected prefixed and suffix.

End Product

After 4-5 hours, I had finshed and it came out better than I hoped!
Head over to the gitHub Repo to see some exmaples and check the script out for your self. :grinning_face_with_smiling_eyes:

I had a lot of fun making this, and feel free to share any hilarious results you get here!
And don’t forget to let me know what you think. Thank you! <3

Hi! Interesting project.

Some thoughts:

  1. Avoid hardcoded year with variable name currentYear. In next year the current year will be 2023) So name of variable will confuse. If you always want current year then try to use Date class, see Date - JavaScript | MDN
  2. Instead of print fact inside genFact return fact from it. So you can reuse function, for example, to generate text with multiple facts.
  3. Use template-style syntax for substitusion keywords like {KEYWORD}. So you can use KEYWORD (without brackets) in source sentence without replacement. This is not critical, but will help in some situations.
  4. Divide code and data. You can store your arrays in another files or database. So you can add new combinations without changing code.

Thanks for sharing!

PS Sorry for my English)

1 Like

Heyo o/

Thank you for the detailed response!

  1. This is a great suggestion! While I knew I would need to manually update the value, I hadn’t thought about the variable name being confusing in the future. Will defiantly remember this for future projects!
    I will probably go back and change the name to arbitrary year or add a comment, since Date class is a little out of scope for this project.
  2. To tell the truth I hadn’t considered this. :see_no_evil:
    While I do not expect to be using this project in anything else, or expanding it in the future, that doesn’t mean others won’t!
  3. I actually played around with this idea, but since I didn’t think I would ever need to use KEYWORDs with out replacement I with went with no template-style syntax to save my self some key strokes. :sweat_smile:
  4. Actually tried putting the data into a JSON file and reading from it, but with the self imposed dead line I decided to scrap it and keep the data in the same file. Will put this on a to-do list once the course goes over Node.JS/Back-end in more detail!

Thank you again! Wish I could like your post more than once! :rofl:


About item 3. As software developer you have to think ahead. You do not know what users will do with your app. And they will do very strange things in my expirience) So using KEYWORD without replacement is not the strangest thing)

This is only advice for future projects)

Good luck!

1 Like