Build a Lunch Picker Program -

Tell us what’s happening:

Hiya, I’m having trouble with the final two tests, pertaining to the showLunchMenu() function - the <…rest> keyword seems to really be stumping me, as both tests pertaining to it require spaces between all the items shown and using …rest doesn’t seem to allow that. Either 29 or 30 passes depending on the presence of a comma after ${c}. Thanks in advance!

Your code so far

let lunches = [];

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

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

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

function removeFirstLunch(menu){
  if (menu.length == 0) {
    console.log("No lunches to remove.")
  } else {
    let removed = menu.shift();
    console.log(`${removed} removed from the start of the lunch menu.`)
    return menu;
  }
}

function getRandomLunch(menu){
  // generate a random integer between one and the length of the parameter.
  const randomIndex = Math.floor(Math.random() * menu.length);
  if (menu.length == 0) {
    console.log("No lunches available.")
  } else {
    console.log(`Randomly selected lunch: ${menu[randomIndex]}`)
  }  
}

function showLunchMenu(menu){
  if (menu.length == 0) {
    console.log("The menu is empty.")
  } else {
    let [a, b, c, ...rest] = menu;
    console.log(`Menu items: ${a}, ${b}, ${c}, ${rest}`)
  }
}

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

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

/* for future me - literally everything is working apart from showLunchMenu(menu). I'm having trouble with destructuring the array dynamically - when you try to use the ...rest keyword in a console log, it doesn't seem to put the requisite spaces between the items. So it says Greens,Corns,Beans when it should say Greens, Corns, Beans etc. and the two tests at steps 29 and 30 are different lengths, so i can't just destructure and stick the first three items into a template literal either.*/

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:155.0) Gecko/20100101 Firefox/155.0

Challenge Information:

Build a Lunch Picker Program - Build a Lunch Picker Program

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-lunch-picker-program/66db529d37ad966480ebb633.md at main · freeCodeCamp/freeCodeCamp · GitHub

Hi @bamclowder

What could you use instead of destructuring?

That will only work for a specific length of array elements.

Happy coding

oh! figured something else out. thanks for the wee push in the right direction.