Build a Lunch Picker Program - Build a Lunch Picker Program

Tell us what’s happening:

Greeting! Could someone please give me the answer and explain it to me?
I failed step 4, 8, 13, 18, 24, 29 and 30.
I don’t log the correct answer.
Have a nice day!

Your code so far

let lunches = [];

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


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


function removeLastLunch(array) {
  let suppEnd = array.pop();

  if (array.length > 0) {
  console.log(`"${suppEnd} removed from to end of the lunch menu."`);
  return array;
  }

  else {
  console.log("No lunches to remove.");
  return array;
  }
};


function removeFirstLunch(array) {
  let suppStart = array.shift();

  if (array.length > 0) {
  console.log(`"${suppStart} removed from the start of the lunch menu."`);
  return array;
  }

  else {
  console.log("No lunches to remove.");
  return array;
  }
};


function getRandomLunch(array) {
  let randomNum = Math.floor(Math.random() * (array.length - 1));
  let randomLunch = array[randomNum];

  if (array.length > 0) {
  console.log(`"Randomly selected lunch: ${randomLunch}"`);
  }

  else {
  console.log("No lunches available.");
  }
};

function showLunchMenu(array) {

  if (array.length > 0) {
  return console.log(`"Menu items: ${array.join(', ')}"`);
  }

  else {
  return 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/141.0.0.0 Safari/537.36

Challenge Information:

Build a Lunch Picker Program - Build a Lunch Picker Program

this is not allowed

let’s see what can be done with your code tho

you are always including quotes in the strings printed to the console, are you sure that’s what you are asked to do?

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

(step 4) If i remove quote, i log : Tacos added to the end of the lunch menu. But the lab want "Tacos added to the end of the lunch menu."

it does not want the quotes, promise

for this one, consider, there was one element in the array, you remove it on line 1 of the function, but now array.length > 0 is false, so you print “No lunches to remove”, do you think that’s correct?

I remove all the quote, i pass step 4, 8, 13, 18, 29 and 30. Thanks you.

For the removeLastLunch( ), first i check if there is something inside my array with array.length and if so, i remove it.

I only have step 24 left.

24. 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.

Can i refresh my code (if possible) or i must to copy/paste in the reply section?

please put it in a new post in this topic, updating the code in the first post would create confusion

let lunches = ;

function addLunchToEnd(array, string) {

array.push(string);

console.log(`${string} added to the end of the lunch menu.`);

return array;

};

function addLunchToStart(array, string) {

array.unshift(string);

console.log(`${string} added to the start of the lunch menu.`);

return array;

};

function removeLastLunch(array) {

if (array.length > 0) {

let suppEnd = array.pop();

console.log(`${suppEnd} removed from the end of the lunch menu.`);

return array;

}

else {

console.log(“No lunches to remove.”);

return array;

}

};

function removeFirstLunch(array) {

if (array.length > 0) {

let suppStart = array.shift();

console.log(`${suppStart} removed from the start of the lunch menu.`);

return array;

}

else {

console.log(“No lunches to remove.”);

return array;

}

};

function getRandomLunch(array) {

let randomNum = Math.floor(Math.random() * (array.length - 1));

let randomLunch = array[randomNum];

if (array.length > 0 && randomLunch !== undefined) {

return console.log(`Randomly selected lunch: ${randomLunch}`);

}

else {

return console.log(“No lunches available.”);

}

};

function showLunchMenu(array) {

if (array.length > 0) {

return console.log(`Menu items: ${array.join(', ')}`);

}

else {

return console.log(“The menu is empty.”);

}

};

24. 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.

Can you help me with this?

would this ever get the last item in the array?

Math.floor(Math.random() * array.length);

Thank you i pass all step. Have a good day.