Mixed Messages - "Almost Definitely Fake Facts"

Hi Everyone!

I just finished my Mixed Messages project and it was a lot of fun! It took me approximately 30-45m to complete it. It wasn’t difficult; just fun to use the knowledge I acquired so far at CodeCademy. I appreciate any feedback you all can give me. I also appreciate feedback on the README.md file (I have never done one before, nor read many).

Here is the GitHub Repository:

https://github.com/bbrasil1891/mixed-messages

Thank you for taking the time to give me some feedback!

Hey! I like your approach. If I could, I would like to suggest some refactoring.

on line 32 down to line 46 has a lot of defining going on! Maybe consider extracting some logic to helper methods? I am having a hard time giving any practical advice in this situation because it would change so much of your original code.

My approach would not be to push the factory object to an array, but to return an object with some setters and getters. You could hard code arrays like I did and insert them programmatically into the factory object. The object could even have some instance methods that could take some of the workload out of your outputRandomFact() function on line 30

Check mine out, let me know what you think:
main.js

Hi, Mike!

Thank you for your feedback!

For the defining between lines 32 and 46, my thought process to justify adding the many variables was to make the code more readable by someone else, and by myself in the future. However, I see your point. Maybe simplifying it in fewer lines would make it more readable as well (maybe even more than using many variables). I did go back and changed my code to decrease the number of definitions. Do you know any resources I can use to learn more about code readability vs. code length, best practices in regards to this topic, etc?

About hard-coding the arrays, I thought about it too, but decided to do with the factory function approach in case I decide to do a website that a user can add new facts to the database. I suppose I could make the website able to add to the hard-coded arrays, but, again, I thought readability is improved by using factory function (plus I get to practice that concept a little bit more).

About your main.js file, I took a look at it and it looks good. If I can suggest some food for thought:

  1. Hard-coding the size of the arrays using the variable maxMsgIndex works, but limits your code to just that. Instead, you could use the .length property in one of the arrays to determine that number dynamically, in case you modify them later. Be careful in this case, however, to not have one of the arrays with more indexes than another, as this would lead to a crash.
  2. You declared the generateRandomIndexArray after its first use. While this is ok and works, I believe one of the CodeCademy lectures mention this is not good practice.

Other than that, it is concise and works great!

Thanks again for your feedback, Mike. I appreciate it!