Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

M-5 Pick a random food to eat

Are you hungry but you don't know what to eat for today?

Create an array with 7 different favorite foods of yours.

ex. favFoods = ['bananas', 'rice', 'chocolate', 'pizza', 'mett', 'bread', 'onions'];

Create a function that picks randomly one of this seven foods and prints it to the console.

Bonus: Create a function that actually selects randomly one of these for every day of the week and  prints:

'On Monday i will have bananas'

'On Tuesday i will have pizza'

'On Wednesday i will have onions'

etc.

hint: You may want to create another array to hold there, the days of the week. Also when a food is selected it cannot be reselected, that means you need to remove it from the array. Maybe the splice method that any array provides will help in this case. (Check the array methods inside the array section).

arr.splice(which index to start removing, how many elements)

Pick a random food for today!

Kostas Diakogiannis
Module by Kostas Diakogiannis, updated more than 1 year ago
No tags specified