Build a Lunch Picker Program - Build a Lunch Picker Program

Tell us what’s happening:

my code doesn’t pass although it works

Your code so far

let lunches = [];
function addLunchToEnd(lunches, newLunch) { 
lunches.push(newLunch);
console.log(newLunch + " added to the end of the lunch menu.");
return lunches;
}
console.log(addLunchToEnd(lunches,"Tacos"));

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

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

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

function getRandomLunch(lunches) {let random = Math.floor(Math.random() * lunches.length);
if (lunches.length == 0) {return "No lunches available."
  }

else if (lunches.length !== 0){return "Randomly selected lunch: " + lunches[random]}
  }
console.log(getRandomLunch(lunches));

function showLunchMenu(lunches){let shahd = lunches.join(' ,');
if (lunches.length !== 0) {console.log("Menu items: " + shahd);}
else if(lunches.length == 0) {return "The menu is empty.";}
}
console.log(showLunchMenu(lunches));

Your browser information:

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

Challenge Information:

Build a Lunch Picker Program - Build a Lunch Picker Program

Your functions are checking the array length after the fact. If you have an empty array, there’s nothing to pop(), etc.

@fcc4b6d10c4-b540-4e2 is correct.

However, there are other issues too such as:

You should be logging this message to the console.

You should also format your code, as it’s much easier to read and debug if it’s correctly formatted.

thank you this helped me

1 Like

thank you this also worked