Random Mixed Messages

I feel that this project was an easy project and just enough to get a feel of how it is to code on my own computer instead of using the IDE on Codecademy!

This project took me about 20 minutes to complete, with most of the time being taken to think of the messages


I think this is the purpose of this project

I would like to give one point of feedback, here:

    return Math.floor(Math.random()*10)

10 is what I call a magic number, if you expand the project and look back to this project 3 months down the line, do you still now what this number means?

also, if you change the amount of elements in one of the lists, your code might show unexpected behavior.

I would go for giving the function a parameter:

function randomNumber(lst)

and then use the length of the list to generate the random number. Now you can freely add or remove elements from your list

actually, if you want to take it a step further, and rename your randomNumber function to randomElement, and use the function to return a random element from your list

Yes, thank you! The suggestions you have made make sense and allow the program to be more flexible.

I have implemented the aforementioned changes!

1 Like