Mixed Messages/ first time sharing a project

Sep 26 - Hello, this is the first time I post here

I wrote this basic randomly changing message, would be neat to hear some feedback, suggestions, etc.

stuff I thought about:
naming the lists appropitaly, adding more dialouge options (and thus increasing the random numbers), and expanding the message to incorparte more story (would also require more lists, not an issue though)

the project itself didn’t took long, as it was simple.
link: GitHub - Gmike47/mixed_messages: a Codecademy message generator project

Have a good day

1 Like

The first thing to do in this program would be to make it more scalable by wrapping the random number coding in a function and then making the multiplier be equal to the length of an array passed into it so it will always produce an index that will correspond to an item within the array.

it could look something like this:

const getRandomItem = (array) => {
 let x = Math.floor(Math.random()*array.length);
return array[x];

Then you could call the function instead of setting the values individually. You can even call the function within the console.log line iirc.

If you’d prefer not to pass the array into a function, just using a function to generate a number could help here too:

const getRandNum = (num) => {
return Math.floor(Math.random()*num);

While the script might function, I always try to look back over things to see if I’ve done something a bunch of times and see if somehow there’s a way to make that into a function or otherwise streamline it. It’s not always so…pressing of an issue with such little workload and such small amounts of code, but it will help if you ever expand the project.

Thank you for the tip, leaner code is always better