Build a Lunch Picker Program - Build a Lunch Picker Program

Tell us what’s happening:

I am having trouble with tests #12 & #13 … so far

Both relate to the removeLastLunch function - i’m logging the results as i go and they appear to be correct

Your code so far

let lunches = [];

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




function addLunchToStart(arr, str) {
  lunches = [...arr];
  lunches.unshift(str);
  console.log(str + " added to the start of the lunch menu.");
  return lunches;
}



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

removeLastLunch(["Stew", "Soup", "Toast"])


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



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



function showLunchMenu(arr) {
  const [...rest] = lunches
  if (lunches > 0) {
    console.log("Menu items: " + rest)
  } 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/139.0.0.0 Safari/537.36 Edg/139.0.0.0

Challenge Information:

Build a Lunch Picker Program - Build a Lunch Picker Program

https://www.freecodecamp.org/learn/full-stack-developer/lab-lunch-picker-program/build-a-lunch-picker-program

results of my console.logs:

[ 'Stew', 'Soup', 'Toast' ]
[ 'Stew', 'Soup' ]
Toast
2
Toast removed from the end of the lunch menu.

Think about the order in which you are doing things in this function.

  1. copying from arr to lunches
  2. removing the last element
  3. then logging the appropriate string

isn’t that the correct order?

Give that some more thought, please.

ive tried removing the element first, then copying what is left to “lunches” - still doesn’t work.

both ways seem to correct to me anyway

What happens if you pass in an empty array?

are you asked to leave the passed in array unchanged or to change it?