Mixed Messages Generator

This is my first attempt to this project. It is really fun, especially looking up quotes that I likes.

Please take a look, and let me know what you think :slight_smile:

Hello,

Iā€™m fairly new to coding so maybe Iā€™m way off base but I think you have an error in the way you wrote your ā€˜messagesā€™ array. You have an array of arrays which could work but the rest of your code doesnā€™t work properly with that format. I think you need to break up your inspirational quotes and save them individually to variables. Then you can add all the variables to an array and use your code properly. Hope Iā€™m not wrong and if not I hope what I said helps, keep coding! :slight_smile:

-Logan Thomas

Welcome, @mphbo. Oneā€™s first response to the above is, ā€˜What?ā€™ That would be a less than suitable way to work with data. Thatā€™s why we have data structures that support key-value pairs. The keys are the variables, only now they are called, ā€˜variableNames.ā€™

An array is also very useful alternative for housing small but similar objects.

    platonic_solids = [
      {
        shape: 'tetrahedron',
        sides: 4,
        face: 'triangle'
      },
      {
        shape: 'cube',
        sides: 6,
        face: 'square'
      },
      {
        shape: 'octahedron',
        sides: 8,
        face: 'triangle'
      },
      {
        shape: 'dodecahedron',
        sides: 12,
        face: 'pentagon'
      },
      {
        shape: 'icosahedron',
        sides: 20,
        face: 'triangle'
      }
    ]
console.log(
  platonic_solids[platonic_solids.find(x => x.sides === 12)]
)
// { shape: 'dodecahedron', sides: 12, face: 'pentagon'  }

I totally understand what you mean. But with the way the code in the github repository is, it doesnā€™t allow for arrays within arrays. The entire array will be returned or logged, which I donā€™t believe is intended?

After looking at the code one sees what you mean. There is no discernment within the array. However it can be solved without extra variables.

Bottom line, variables are pollution.

I agree, makes sense, I need to work on reducing my variable use to make things simpler. However,

Bottom line, we should be reading code before making comments on said code.

My comment was not on the code but on your suggestion to use separate variables. I didnā€™t need to read the code until after your second comment.

You needed to read the code to understand the context of the situation.

Hi @mphbo and @mtf , thank you very much for your suggestions. I went back to check on my code, I did notice the extra comas in my messages array, which I corrected.

@mphbo When you said that the rest of the code didnā€™t work properly, I am not quite sure I get what you mean.

My thought process is:

  • generate the random index to pull out the data
  • then format the pairing data into a group of 3 sentences

Can you expand more on your thoughts? Do you mean because the elements in the sentences are all from the same array, hence it was not random generated ā€œenoughā€ ? Or if there is other parts that I am missing? I would really appreciate any feedbacks, so I can improve :slight_smile:

@mtf If you have more thoughts on my code, I would love to get some feedback from you too, so I can know how to improve my code :slight_smile:

1 Like

No problem at all. Looking at your code now it looks like I may have been somewhat mistaken.

I thought you wanted each quote to be completely random. As if three quotes would be taken randomly from all of your quotes if that makes sense. Sorry, I just have been trying to follow codecademyā€™s recommendations by reviewing other peopleā€™s work but I am still fairly beginner :blush:

I see what you mean. I thought about that, but then, I might have to consider how to pair the authors and the quotes, hence I chose this way.

With that said, I am not happy about my current solution, as the messages are a bit hard-coded. I would have prefer to have the array just include [mood, author, quote]. I am considering whether I can use a .map() to format the array element before .forEach() :nerd_face: