Build a Lunch Picker Program - Build a Lunch Picker Program

Tell us what’s happening:

I can’t pass the 24, 28, 29, and 30. Can someone please explain to me where i am getting it wrong?

  1. When the input array is not empty, the function getRandomLunch should log a string in the format Randomly selected lunch: [Lunch Item] to the console.

  2. When the input array is empty, the function showLunchMenu should log the string “The menu is empty.” to the console.

  3. showLunchMenu([“Greens”, “Corns”, “Beans”]) should log “Menu items: Greens, Corns, Beans” to the console.

Your code so far

const lunches = [];
function addLunchToEnd(lunch, item){
  lunch.push(item)
  console.log(`${item} added to the end of the lunch menu.`)
  return lunch;

};

function addLunchToStart(lunches, Sushi){
  lunches.unshift(Sushi)
  console.log(`${Sushi} added to the start of the lunch menu.`)
  return lunches;
}

function removeLastLunch(lunches){
  if (lunches.length === 0){
    console.log("No lunches to remove."); 
  }else{
    let removedItem = lunches.pop();
    console.log(`${removedItem} removed from the end of the lunch menu.`)
  }
  return lunches
};

function removeFirstLunch(lunches){
  if (lunches.length === 0){
    console.log("No lunches to remove.")
  }else {
    let removedFirstStr = lunches.shift();
    console.log(`${removedFirstStr} removed from the start of the lunch menu.`)
  }
  return lunches
};


function getRandomLunch(lunches){
  let randomLunch = Math.floor(Math.random() * lunches.length);

  if (lunches.lenght === undefined){
    console.log("No lunches available.")
  }else {
    return `Randomly selected lunch: [Lunch Item ${randomLunch}]`
  }

};

function showLunchMenu(lunches){
  let showMenu = lunches
 if (lunches === 0){
   console.log("The menu is empty.")
 }else {
   return `Menu items: ${showMenu}`
 }
};



Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36 Edg/147.0.0.0

Challenge Information:

Build a Lunch Picker Program - Build a Lunch Picker Program

Hi @Only1AGU,

The brackets in the instruction message are only meant to be a placeholder for the variable and are not meant to be used literally in your message string.

Check your condition in the if statement. Will the lunches array ever strictly equal 0?

Check your spacing against what is expected. You may need to do something more than just return the array.

Edit: Please log your variables to make sure they are what you expect:

[quote=“Only1AGU, post:1, topic:786539”]
let randomLunch = Math.floor(Math.random() * lunches.length);
[/quote]

Happy coding!

You have a typo in getRandomLunch