mercredi 13 mai 2020

Why does object in array return undefined? [duplicate]

My randomItem() function is returning veggies as undefined. Any idea why?

data = {
  bread: ["white", "italian 5 grain", "whole wheat"],
  cheese: ["cheddar", "muenster", "provolone", "swiss", "white american", "yellow america"],
  meat: ["oven roasted turkey", "oven roasted beef", "maple glazed ham", "black forest ham", "buffalo chicken breast", "bologna", "corned beef", "salsalito turkey", ],
  veggies: ["banana peppers", "black olives", "garlic pickles", "cucumbers", "dill pickles", "green peppers", "jalapeno peppers", "lettuce", "onions", "spinach", "tomato", "salt", "black pepper", "oregano", "oil and vinegar"],
  condiments: ["honey mustard", "spicy mustard", "mayo"],
  extras: ["avocado", "hummus", "guacamole", "bacon"],
  bake: ["pressed", "toasted"]
}

const getRandom = (min, max) => {
  return Math.floor((Math.random() * (max - min) + 1) + min);
}

function randomItem(item) {
  const random = getRandom(0, item.length - 1);
  console.log(data.item[random]);
}

randomItem(veggies);



Aucun commentaire:

Enregistrer un commentaire