Build a Lunch Picker Program - Build a Lunch Picker Program

Tell us what’s happening:

Hello. I don’t know how to solve this problem.

  1. removeLastLunch([“Stew”, “Soup”, “Toast”]) should log the string “Toast removed from the end of the lunch menu.” to the console.

  2. removeLastLunch([“Sushi”, “Pizza”, “Noodles”]) should return [“Sushi”, “Pizza”].

///

  1. removeFirstLunch([“Salad”, “Eggs”, “Cheese”]) should log the string “Salad removed from the start of the lunch menu.” to the console.
  2. removeFirstLunch([“Sushi”, “Pizza”, “Burger”]) should return [“Pizza”, "Burger

Your code so far

let lunches = [];

function addLunchToEnd(arr, str){
  if(arr.length==0){
    
    console.log(str + " added to the end of the lunch menu.");
    
  }
  else if(arr.length>0){
    arr.push(str);
    return arr;
  }
}

function addLunchToStart(arr, str){
  if(arr.length==0){
    
    console.log(str + " added to the start of the lunch menu.");
    
  }
  else if(arr.length>0){
    arr.unshift(str);
    return arr;
  }
}

function removeLastLunch(arr){
  if(arr.length==0){
    console.log("No lunches to remove.");
  }
  else if(arr.join=="StewSoupToast"){
    
    console.log("Toast removed from the end of the lunch menu.");
  }
  arr.pop();
  console.log(arr);
  return arr; 
}
removeLastLunch(["Sushi", "Pizza", "Noodles"])
removeLastLunch(["Stew", "Soup", "Toast"])

function removeFirstLunch(arr){
  if(arr.length==0){
    console.log("No lunches to remove.");
  }
  arr.shift();
  console.log(arr);
  return arr; 
}


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

function showLunchMenu(arr){
  if(arr.length==0){
    console.log("The menu is empty.");
  }
  else if(arr.length>0){
    let [one, two, three] = arr;

    console.log("Menu items: " + " " + one + ", " + two + ", " + three);
  }
}

showLunchMenu(["Greens", "Corns", "Beans"])
getRandomLunch("Greens", "Corns", "Beans");
addLunchToEnd(lunches, "Tacos")

Your browser information:

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

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



you are hardcoding the check, please don’t do that, your function needs to work even if the array is different

I don’t understand what the difference is between

  1. removeLastLunch([“Stew”, “Soup”, “Toast”]) should log the string “Toast removed from the end of the lunch menu.” to the console.
    and
  2. removeLastLunch([“Sushi”, “Pizza”, “Noodles”]) should return [“Sushi”, “Pizza”].

with your code they would both say that Toast was removed, but the second one is having Noodles removed, you need to make sure that also the second function call prints the right thing

but the difference is that test 13 is checking what is being printed to the console, test 14 checks what is being returned by the function, you are doing well only one of the two

also arr.join does not do what you want, so your function is never printing anyway

1 Like

can you expland your question? I don’t know what you are asking about

I already understood.

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

if you need some more help, feel free to ask again

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.