Build a Lunch Picker Program - Build a Lunch Picker Program

Tell us what’s happening:

I’m unable to pass test #26, which says that the function showLunchMenu should have a single parameter. My function only has a single parameter but it doesn’t pass the test. Any idea why? Thanks in advance. - Dtrizzle

Your code so far

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

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

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

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

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

function showLunchMenu(arr = []) {
    if (arr.length > 0) {
        console.log(`Menu items: ${arr.join(', ')}`);
    } else {
        console.log("The menu is empty.");
    }
}

const lunches = [];
addLunchToEnd(lunches, "Tacos");
addLunchToEnd(["Pizza", "Tacos"], "Burger");
addLunchToStart(lunches, "Sushi");
addLunchToStart(["Burger", "Sushi"], "Pizza");
removeLastLunch(["Sushi", "Pizza"], "Noodles");
removeFirstLunch(["Salad", "Eggs", "Cheese"]);
showLunchMenu();
showLunchMenu(["Greens", "Corns", "Beans"]);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:135.0) Gecko/20100101 Firefox/135.0

Challenge Information:

Build a Lunch Picker Program - Build a Lunch Picker Program

Welcome to the forum @dtrizzle

Try it without the assignment.

Happy coding

That worked! Thank you. Given that it meets the requirements (“single parameter”) as listed, should I report a bug? Just thinking about people in the future who might have the same issue.

Hi there. You already have array []to store data, doesn’t need to assign a new one to the parameter.

It seems the tests uses the length property on the function, but default parameters do not count toward that length, so your function was failing the test as the Function.length was 0 instead of the expected 1