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
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
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!
-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:
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
@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
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
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()