Mixed Messages - Art Piece Ideas Generator

Hi! I have done a first draft of the Mixed Messages Project, and have created a Random Art Piece Generator that gives the user suggestions for a new piece.

Here’s the GitHub repository: GitHub - byoriolserra/mixed-messages

It’s quite simple and I am planning on maybe expanding it a little to accept user input, so that the program better adapts to the artist’s preferences.

I’d be really grateful if you could give me a bit of feedback on optimising the code.
Thanks!

Nice and clean solution!
What you could also do in order to make the code just a bit cleaner, is to create a separate function for the generation of the random index dependent on the array length. You could then pass that as the index, like so:

const generateArrayNumber = (arr) => {
    return Math.floor(Math.random() * arr.length);
}

const messageFactory = () => {
    let pickedMedium = ideas.medium[generateArrayNumer(ideas.medium)];
    //...

All in the concept of DRY: Don’t Repeat Yourself. Seperate functions help you do that! :slight_smile:

You could even go as far and let the generateArrayNumber return the message directly:

const generateRandomMessage = (arr) => {
    let index = Math.floor(Math.random() * arr.length);
    return arr[index]
}

But I like your version as well :smiley: