Build a Lunch Picker Program - Build a Lunch Picker Program

Tell us what’s happening:

Hi. I’m really struggling to know why I can’t pass any of the log to console tests for my first four functions. I’m passing all other tests and just can’t see what’s wrong with those console.log() statements. Any help would be very much appreciated.

Your code so far

const lunches = [];

function addLunchToEnd(lunches, lunchItem) {
  lunches.push(lunchItem);
  console.log(`${lunchItem} added to the end of the lunch menu.`);
  console.log(lunches);
  return lunches;
}

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

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

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

function getRandomLunch(lunches) {
  const randomLunch = lunches[Math.floor(Math.random() * lunches.length)];
  if (lunches.length > 0) {
    console.log(`Randomly selected lunch: ${randomLunch}`);
  } else {
    console.log(`No lunches available.`);
    return randomLunch
  }
} 

function showLunchMenu(lunches) {
  if (lunches.length > 0) {
    console.log("Menu items: " + lunches.join(", "));
  } else {
    console.log("The menu is empty.");
  }
}

Your browser information:

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

Challenge Information:

Build a Lunch Picker Program - Build a Lunch Picker Program

  1. addLunchToEnd(lunches, "Tacos") should log the string "Tacos added to the end of the lunch menu." to the console.

your extra console.log of lunches is making you fail the test.

Edit*** In fact remove all your console.logs of lunches and you should pass the lab

2 Likes

Hi,
you should return your console.log()s. For example, in the first function, the error 4 says:

addLunchToEnd(lunches, "Tacos") should log the string "Tacos added to the end of the lunch menu." to the console. but in your function, you’re returning lunches. You have the consol.log statement above it with the correct text but you’re not logging that to the console.
Just like that, you may want to check your other functions, and some of them might even be returning the wrong text.
Good luck!

1 Like

Thank you. I think I’d been looking at it so long, I just couldn’t see it.

1 Like

I am getting while working with step 5 addLunchToEnd(["Pizza", "Tacos"], "Burger") should return ["Pizza", "Tacos", "Burger"], I don’t know what to do

please create your own topic to ask for help

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Get Help > Ask for Help button located on the challenge.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.