Mixed Messages - Funny Discourse Generator

Hi All,

this is my Mixed Messages project: the Funny Discourse Generator.
Besides the code, I’ve tryed to practice the classes about Git, GitHub, Vs Code, Terminal commands, Markdown and formating README.md file in GitHub. However, I couldn’t form a team because the project is too simple and I had no idea about how to share the tasks.
The sfwre generates politician empty and abstract discourses.
It was easy to develop and tooks me about 3 hours to write it.
All comments are wellcome, mainly those negatives.

//Declare arrays with the fragments of text. const fragment1 = [ 'Dear people of my country, ', 'We should never forget that ', 'The experience shows us that ', 'It\'s not too much to insist that ', 'I think that it\'s very important to emphasize that ', 'The encouragement in the technological progress as well as ', 'If we ponder, we see that ', 'Today, ', 'In the context of the current policy, ', 'All data points out that ', 'As a result, ', 'This awesome project makes me believe that ' ]; const fragment2 = [ 'our effort to accomplish this challenge ', 'a great complexity of studies ', 'the new structural model, recommended here, ', 'the expansion of our activity ', 'the assess of those results ', 'the development of different ways of acting ' ]; const fragment3 = [ 'compels us to the analyses ', 'plays a fundamental role in the formulation ', 'requires precision and definition ', 'offers an excellent opportunity for the verification ', 'takes position in the configuration ', 'gives focus to the importance ' ]; const fragment4 = [ 'of our financial and administrative goals.', 'of basic politics toward the success of the program.', 'of specific conditions for each business.', 'of our team building potential.', 'of the government attributions.', 'of the procedures.' ]; //Declare randomized fragments arrays let seq1 = []; let seq2 = []; let seq3 = []; let seq4 = []; //Declare the string for the output of the discourse let discourseString = ''; //Generates a random id function randId(numElements) { return Math.floor(Math.random() * (numElements)); } //Populate the randomized arrays. do { let currRandId = randId(12); if (!seq1.includes(currRandId)) { seq1.push(currRandId); } } while (seq1.length <= 5); do { let currRandId = randId(6); if (!seq2.includes(currRandId)) { seq2.push(currRandId); } } while (seq2.length <= 5); do { let currRandId = randId(6); if (!seq3.includes(currRandId)) { seq3.push(currRandId); } } while (seq3.length <= 5); do { let currRandId = randId(6); if (!seq4.includes(currRandId)) { seq4.push(currRandId); } } while (seq4.length <= 5); //Create the string with randomized array elements for (let i = 0; i <= 5; i++) { discourseString = discourseString + fragment1[seq1[i]] + fragment2[seq2[i]] + fragment3[seq3[i]] + fragment4[seq4[i]] + '\n' } //log the discourse console.log(discourseString);


Thoughts and recommendations:

  1. Do not use hardcoded array size for index generation. What if your arrays will contain more elements in future? You will need to change your code for index generation. See Array.length method: JavaScript Array length Property
  2. Instead of repeating code in lines 56-79 try to extract a function and then simply use it four times with fragments array as parameter.
  3. And about your second TODO. You do not need PostgreSQL for so small project, look at SQLite: https://www.sqlite.org

Good work!

1 Like

Thank you! I will search for all this material :slightly_smiling_face:

1 Like