Build a Lunch Picker Program - Build a Lunch Picker Program

Tell us what’s happening:

// running tests
8. addLunchToStart(lunches, “Sushi”) should log the string “Sushi added to the start of the lunch menu.” to the console.
13. removeLastLunch([“Stew”, “Soup”, “Toast”]) should log the string “Toast removed from the end of the lunch menu.” to the console.
18. removeFirstLunch([“Salad”, “Eggs”, “Cheese”]) should log the string “Salad removed from the start of the lunch menu.” to the console. Please help me out guys! Been working on this for over an hour! ugh!

Your code so far

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



function addLunchToStart(arr, str){
console.log(`${str} Sushi added to the start of the lunch menu.`)
arr.unshift(str);
return arr;
}
let lunch = ["Burgers", "Sushi"];
addLunchToStart(lunch, "Sushi")
console.log(addLunchToStart(["Burger", "Sushi"], "Pizza"));



function removeLastLunch(deletedFoods){
  if (deletedFoods.length === 0) {
  console.log("No lunches to remove.");
  return deletedFoods;
  }

let removedLunch = deletedFoods.pop();
console.log(`${removedLunch} removed from the lunch menu.`);
return(deletedFoods);
}

removeLastLunch(["Stew", "Soup", "Toast"]);
console.log(removeLastLunch(["Sushi", "Pizza", "Noodles"]));

function removeFirstLunch(deleteFood) {
  if(deleteFood.length === 0){
    console.log("No lunches to remove.");
    return deleteFood;
  }
let removedLunch = deleteFood.shift();
console.log(`${removedLunch} remove from the start of the lunch menu.`);
return deleteFood;
}
console.log(removeFirstLunch(["Salad", "Eggs", "Cheese"]));
console.log(removeFirstLunch(["Sushi", "Pizza", "Burger"]));
console.log(removeFirstLunch([]));



function getRandomLunch(lunchArray){
  if(lunchArray.length === 0){
    console.log("No lunch available");
  } else {
    const randomIndex = Math.floor(Math.random()*lunchArray.length);
    console.log(`Randomly selected lunch: ${lunchArray[randomIndex]}`);
  }
}
getRandomLunch(["Sandwich", "Salad", "Sushi", "Pizza"]);
getRandomLunch([]);



function showLunchMenu(menuItems){
  if(menuItems.length === 0){
    console.log("The menu is empty");
  }else{
    console.log("Menu Items: " + menuItems.join(","));
  }
}
showLunchMenu(["Greens", "Corn", "Beans"]);
showLunchMenu(["Pizza", "Burger", "Fries", "Salad"]);
showLunchMenu([]);



Your browser information:

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

Challenge Information:

Build a Lunch Picker Program - Build a Lunch Picker Program

Have you looked at the output in console? There appear to be many sushi in it…

1 Like

It looks like you have hard-coded conditionals or variables that check for specific expected values. That is not solving this problem in the general case. Imagine if you were given different input values. Would your code be able to solve those problems?

To find out more about what hard-coding is or about why it is not suitable for solving coding questions, please read this post: Hard-coding For Beginners

Let us know if you have a question about how to make your code more flexible.

1 Like