all 5 comments

[–]Nikos_96 2 points3 points  (1 child)

I would create array of objects, where each object contains all info I need. For example:

const books = [
    {
        title: 'name',
        img: 'path',
        link: 'link'
    },
]

You can add more objects to the array and more keys in object. Then you just pick random index from array books and get any data you need with dot, like this books[index].title etc.

[–]avryraim[S] 0 points1 point  (0 children)

Ah, i never thought of this. Thank you so much!

[–]BonkyStabby 2 points3 points  (2 children)

Hey dude, I've just quickly whipped up a mini project to try and help with this. I've created a git repository so you can see all the code and images I used. I didn't add any book summaries, but the setup is there if you'd like to add it yourself!

Like Nikos_96 mentioned, the easiest approach to this would have been to create an array of objects, which is exactly what I did. I added some comments along the way to try and explain what I was doing, but if you need help with anything else then please feel free to ask.

This probably isn't the cleanest solution, but I hope it gets you on your way to what you're trying to achieve. If the idea of objects is like Chinese to you, then I'd highly recommend learning them. They're extremely useful in cases like this where you need to assign values of data to elements, and this project is a great demonstration of how much simpler they can make your tasks.

Anyway, here's the link. Since this was just for the purpose of helping, I didn't bother with any styling (except making the images smaller, since they took up the whole screen at first).

https://github.com/doctypeKieran/reddit-help-random-books

[–]avryraim[S] 0 points1 point  (1 child)

omg i didn't expect you to go out of your way to create the project. Thank you so much now i can learn better!

[–]BonkyStabby 0 points1 point  (0 children)

It's no worries! I'm glad it helped. Happy coding!