Here is my Mixed Messages portfolio project that logs 3 random motivational phrases.
The working file script.js consists of 2 functional parts:
Object tipsObj contains the building blocks from which the random messages are generated. Each key has a value of a nested array and is responsible for generating 1 separate message. It is possible to add personal keys, but it is important to stick to the format of a nested array. An example of the right format: [[‘You’, ‘You definitely’], [‘should’, ‘have to’], [‘keep learning’, ‘get up early’]]. It can generate a phrase like “You should keep learning”
Function mixedMessage(obj) takes the object and generates a new motivational tip by randomly combining the elements from nested arrays inside an array of every key that is added to the object. It pushes a newly generated phrase to a separate array and then it randomly logs 3 phrases from this array of tips.
It took around half a day to complete the project and the hardest part was choosing the format of how the building blocks should be stored. I decided that my project should contain one object inside of which I will store all the building blocks for my tips.
At first, I wanted to use an object with nested objects each of which had arrays of these phrase parts. But it didn’t work out because I couldn’t figure out how to process arrays in a nested object. Finally, I made an object that has keys with nested arrays in their values.
I also wanted to make the tips-generating function that would work steadily if I decided to add some new keys in my object.
My script.js contains comments that explain each part of the program.
Thanks for taking the time to explore my project. I’d be glad to see any comments!