Build a Lunch Picker Program - Build a Lunch Picker Program

Tell us what’s happening:

Having difficulty with the last two steps of this lab. I believe it may have something to do with spacing but not 100% sure. It seems like whatever the issue is, it is the same for both of the last two steps. So close…

Your code so far

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

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

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

addLunchToStart(["Burger", "Sushi"], "Pizza");
console.log(lunches);

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

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

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

function showLunchMenu(arr) {
  if (arr.length === 0) {
    console.log("The menu is empty.");
  }
  else {
    console.log(`\"Menu items: ${arr}\"`);
  }
  return arr;
}
/*console.log(showLunchMenu(["Greens", " Corns", " Beans"]));
console.log(showLunchMenu(["Pizza", " Burger", " Fries", " Salad"]));*/
console.log(showLunchMenu(["Greens", "Corns", "Beans"]));
console.log(showLunchMenu(["Pizza", "Burger", "Fries", "Salad"]));


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.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

Here are some troubleshooting steps you can follow. Focus on one test at a time:

  1. Are there any errors or messages in the console?
  2. What is the requirement of the first failing test?
  3. Check the related User Story and ensure it’s followed precisely.
  4. What line of code implements this?
  5. What is the result of the code and does it match the requirement? (Write the value of a variable to the console at that point in the code if needed.)

If this does not help you solve the problem, please reply with answers to these questions.

29. showLunchMenu(["Greens", "Corns", "Beans"]) should log "Menu items: Greens, Corns, Beans" to the console. This is the first received error with the test requirement.
Copy and Paste of the required code to reduce any chance for typo errors (spacing).
Line 69 corresponds with step 29 and Line 70 corresponds with step 30 - both failing with identical style errors.
User story instructs for a console log of the last created function passing the parameters listed.
69. console.log(showLunchMenu(["Greens", "Corns", "Beans"]));
70. console.log(showLunchMenu(["Pizza", "Burger", "Fries", "Salad"]));

Can you share a comparison of your output and the required output?

"Menu items: Greens,Corns,Beans"
[ 'Greens', 'Corns', 'Beans' ]
"Menu items: Pizza,Burger,Fries,Salad"
[ 'Pizza', 'Burger', 'Fries', 'Salad' ]

This code doesn't have the spaces as needed for the desired code, so I used the commented out code that included the correct spacing and I still received the fail for tests 29 and 30.

Here is the second version that I used adding in spaces after the quotation to generate the correct spacing in the output.

"Menu items: Greens, Corns, Beans"
[ 'Greens', ' Corns', ' Beans' ]
"Menu items: Pizza, Burger, Fries, Salad"
[ 'Pizza', ' Burger', ' Fries', ' Salad' ]
  1. addLunchToEnd(lunches, "Tacos") should log the string "Tacos added to the end of the lunch menu." to the console.

This test passes. Your output:

Tacos added to the end of the lunch menu.

This test fails:

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

See the difference in your output here?

Yes, you do need to add spaces in the output, but No you cannot add them in the function call like that. The function call is this:

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

That’s what will be tested, so you need to make it work with that.

1 Like