Build a Lunch Picker Program - Build a Lunch Picker Program

Tell us what’s happening:

  1. showLunchMenu([“Greens”, “Corns”, “Beans”]) should log “Menu items: Greens, Corns, Beans” to the console.
  2. showLunchMenu([“Pizza”, “Burger”, “Fries”, “Salad”]) should log “Menu items: Pizza, Burger, Fries, Salad” to the console.

showing above error however result does show same so not sure why it showing error.

Your code so far

let lunches=[];
//lunches.push("grape");
//console.log(lunches);
function addLunchToEnd(lunches,item) 
{
  lunches.push(item);
  console.log(`${item} added to the end of the lunch menu.`);
  return lunches;

}
console.log(addLunchToEnd(lunches,"Tacos"));
console.log(addLunchToEnd(["Pizza", "Tacos"], "Burger"));


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


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

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


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

function getRandomLunch(lunches)
{
  let randomNum = Math.floor(Math.random() * lunches.length);
  let randomElement = lunches[randomNum];
  if(lunches.length === 0) 
  {
    console.log("No lunches available.")
  }
  
  
  else {
console.log(`Randomly selected lunch: ${randomElement}`);
}}
console.log(getRandomLunch(["Sushi", "Pizza", "Burger"]));

function showLunchMenu(lunches)
{
 
if (lunches.length == 0)
{
  
  console.log("The menu is empty.");
  return "The menu is empty.";
}
else
{
   console.log(`Menu items: ${lunches}`);
return lunches;
}
}
showLunchMenu(["Greens", "Corns", "Beans"]);

showLunchMenu(["Pizza", "Burger", "Fries", "Salad"]);
console.log(showLunchMenu(0));

Your browser information:

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

Challenge Information:

Build a Lunch Picker Program - Build a Lunch Picker Program

  1. showLunchMenu(["Greens", "Corns", "Beans"]) should log "Menu items: Greens, Corns, Beans" to the console.

When I test this the result is not the same

showLunchMenu(["Greens", "Corns", "Beans"])
Menu items: Greens,Corns,Beans

Comparison:

Menu items: Greens,Corns,Beans
Menu items: Greens, Corns, Beans
let lunches=[];
//lunches.push("grape");
//console.log(lunches);
function addLunchToEnd(lunches,item) 
{
  lunches.push(item);
  console.log(`${item} added to the end of the lunch menu.`);
  return lunches;

}
console.log(addLunchToEnd(lunches,"Tacos"));
console.log(addLunchToEnd(["Pizza", "Tacos"], "Burger"));


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


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

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


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

function getRandomLunch(lunches)
{
  let randomNum = Math.floor(Math.random() * lunches.length);
  let randomElement = lunches[randomNum];
  if(lunches.length === 0) 
  {
    console.log("No lunches available.")
  }
  
  
  else {
console.log(`Randomly selected lunch: ${randomElement}`);
}}
console.log(getRandomLunch(["Sushi", "Pizza", "Burger"]));

function showLunchMenu(lunches)
{
 
if (lunches.length == 0)
{
  
  console.log("The menu is empty.");
  return "The menu is empty.";
}
else
{
   console.log(`Menu items: ${lunches}`);
return lunches;
}
}
showLunchMenu(["Greens", " Corns", " Beans"]);

showLunchMenu(["Pizza", " Burger", " Fries", "Salad"]);
console.log(showLunchMenu(0));

please please please format your code so we can help you

sorry tried to do this way but ……….hope now its better.:slight_smile:

is this your way of adding spaces?

the tests will still call with showLunchMenu(["Greens", "Corns", "Beans"])

Tried this way too but no luck so not sure where am wrong.

showLunchMenu(["Greens", "Corns", "Beans"]);

showLunchMenu(["Pizza", "Burger", "Fries", "Salad"]);

you need to make changes inside showLunchMenu, not to the function call

have you not learned methods to turn an array into a string?

this is what I tries but no luck

function showLunchMenu(lunches)
{
 
if (lunches.length == 0)
{
  
  console.log("The menu is empty.");
  return "The menu is empty.";
}
else
{
   let result = lunches.join(", ");
   console.log(`Menu items: ${result}`);
return result;
}
}

which tests are you failing with this?

TypeError: lunches.join is not a function, have added whole code here again for second check:

let lunches=[];
//lunches.push("grape");
//console.log(lunches);
function addLunchToEnd(lunches,item) 
{
  lunches.push(item);
  console.log(`${item} added to the end of the lunch menu.`);
  return lunches;

}
console.log(addLunchToEnd(lunches,"Tacos"));
console.log(addLunchToEnd(["Pizza", "Tacos"], "Burger"));


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


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

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


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

function getRandomLunch(lunches)
{
  let randomNum = Math.floor(Math.random() * lunches.length);
  let randomElement = lunches[randomNum];
  if(lunches.length === 0) 
  {
    console.log("No lunches available.")
  }
  
  
  else {
console.log(`Randomly selected lunch: ${randomElement}`);
}}
console.log(getRandomLunch(["Sushi", "Pizza", "Burger"]));

function showLunchMenu(lunches)
{
 
if (lunches.length == 0)
{
  
  console.log("The menu is empty.");
  return "The menu is empty.";
}
else
{
   let result = lunches.join(", ");
   console.log(`Menu items: ${result}`);
return result;
}
}
showLunchMenu(["Greens", "Corns", "Beans"]);

showLunchMenu(["Pizza", "Burger", "Fries", "Salad"]);
console.log(showLunchMenu(0));

what do you think happens with 0.join()?

1 Like

not sure why I put it there but deleting it passed the test :slight_smile:, however it should return:

“The menu is empty.”;

but its not

it worked thanks a lot for help :slight_smile: