Feedback Mixed Messages

Hi,

There is my link for mixed messages portfolio. Feel free to give some feedback.

1 Like

Looks like you’ve got it! Great work, my friend. :slight_smile:

Hey there,

Nicely implemented. Although a quick tip for improving the code readability.

I noticed that you are using this piece of code multiple time in your script

Math.floor(breakfast.length * Math.random())

It might be worth looking into making it into a function and call it in your code whenever you want to generate a random number.

Cheers,

Hi,

Thank you for your suggestion !
I totally agree and I have a new implementation for this code.
I would like to have you opinion, and if not asking to much, can I see how you do it.

//function for get a random Item from Array
function getRandomItem(arr) {

// get random index value
const randomIndex = Math.floor(Math.random() * arr.length);

// get random item
const item = arr[randomIndex];

return item;

}

const breakfast = [‘eggs’, ‘bacon’, ‘beans’,‘cerials’,‘pancakes’,‘waffles’,‘toast’,‘milk’];
const lunch = [‘burger’, ‘pizza’,‘steak’, ‘chicken’, ‘hot dog’,‘fish and chips’, ‘sandwich’]
const dinner = [‘chinese Food’, ‘spanish tapas’, ‘beef wellington’, ‘Kidney Pie’,‘lasagne’ ]

const result = For Breafast we recommend ${getRandomItem(breakfast)}, for lunch you can have ${getRandomItem(lunch)}, and a ${getRandomItem(dinner)} for dinner.

1 Like

Yes your new implementation pretty much sums up as how I would have done it. Best.