How to make it shorter

Mixed Message Project

I enjoyed this project!

I think your code is pretty well organized, so congrats to that!
Just when getting the indexes for the words, you have some redundancy in your code. I would delegate that to an extra function like:

const getElement = (prop) => ...

And you don’t need to declare an extra variable for the sentence, you can return it directly:

return `${subj} ${action} ${getElement('link')} ${getElement('objectComplement')}`;
Solution for the getElement function

obj[prop][Math.floor(Math.random() * obj[prop].length)]

Hi! You are right! That extra function cut off all that excessive code inside the mix function!
Thank you so much for your quick response!

1 Like