Mixed Messages - Random future

Hey guys here is my very first project. I found this project really easy and interesting at the same time. I really enjoyed having to create a whole project from start to finish using version control and visual studio code. I think this project took me more or less 1h.

Please feel free to give feedback and suggestions, I will definitely read them!! :slight_smile:

1 Like

this:

    let chosenBuilding = data.buildings[Math.floor(Math.random() * data.buildings.length)];
    let chosenCountry = data.countries[Math.floor(Math.random() * data.countries.length)];
    let chosenAdjective = data.adjectives[Math.floor(Math.random() * data.adjectives.length)];
    let chosenAnimal = data.animals[Math.floor(Math.random() * data.animals.length)];
    let chosenAnimals = data.pluralAnimals[Math.floor(Math.random() * data.pluralAnimals.length)];

feels a bit repetitive. You could make a function to generate a random choice? I think this would improve the program and is a good challenge :slight_smile:

1 Like

Hey @stetim94,

Thanks a lot for the input! I followed your reccomendation and implemented a โ€˜randWord()โ€™ function that takes the desired data.word as an argument and returns a random word from that array.

I was more thinking along the lines of making a separate function:

 const randWord = pointer => {
        // body of randWord function
};

const randMessage = () => {
  // body of randMessage function
}

and not a nested function. So that within the body of the randMessage function you could do something like:

    let chosenAnimal = randWord('animals');