# Build a Lunch Picker Program - Build a Lunch Picker Program

**URL:** <https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [February 20, 2026, 11:43am UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467 "2026-02-20T11:43:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![andre.wilson](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/andre.wilson/32/381994_2.png) [@andre.wilson](https://forum.freecodecamp.org/u/andre.wilson)\
**Post date:** [February 20, 2026, 11:43am UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467/1 "2026-02-20T11:43:39Z")

</div>

### Tell us what’s happening:

Im having trouble in exercise 5, I don’t know what’s happening, when I try to log the pizza in the start it doesn’t work, the output is “,Tacos,Burguer” the pizza doesn’t appear at all can someone help me please?

### Your code so far

```js
let lunches = [];

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

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

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

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

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

function showLunchMenu(array){
  array = lunches
  if(lunches.length !== 0){
    console.log(`Menu items: ${array}`)
  } else if (lunches.length === 0){
    console.log("The menu is empty.")
  }
}

addLunchToEnd();
addLunchToStart();
removeLastLunch();
removeFirstLunch();
getRandomLunch();
showLunchMenu();

```

### Your browser information:

User Agent is: `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.3 Safari/605.1.15`

### Challenge Information:

Build a Lunch Picker Program - Build a Lunch Picker Program

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-v9/lab-lunch-picker-program/build-a-lunch-picker-program)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![pkdvalis](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pkdvalis/32/350571_2.png) [@pkdvalis](https://forum.freecodecamp.org/u/pkdvalis)\
**Post date:** [February 20, 2026, 11:58am UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467/2 "2026-02-20T11:58:12Z")

</div>

Follow the instructions, don’t code by the test:

> 1. You should create a function addLunchToEnd that takes an array as the first argument and a string as the second argument. The function should:

> - Add the string to the end of the array.
> - Log the string [Lunch Item] added to the end of the lunch menu. to the console, where [Lunch Item] is the string passed to the function.
> - Return the updated array.

Does your function do these things?

Remember to use the function parameters in the function, and not global variables like `lunches`

> [@andre.wilson](#):
>
> `array = lunches.push(str); `

How can you confirm if this worked or not?

---

<div class="post-metadata">

**Author:** ![andre.wilson](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/andre.wilson/32/381994_2.png) [@andre.wilson](https://forum.freecodecamp.org/u/andre.wilson)\
**Post date:** [February 20, 2026, 12:00pm UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467/3 "2026-02-20T12:00:19Z")

</div>

doesn’t the first topic ask to create a var named lunch and assign it an empty string?  
“You should declare a variable `lunches` and assign it an empty array to store the lunch items.”  
doesn’t this mean a global var? and then use it on the functions

about the last part, I first did like this “function addLunchToEnd(lunches, str){

lunches.push(str);

console.log(`${str} added to the end of the lunch menu.`);

return lunches;

}”

but the output is this “TypeError: undefined is not an object (evaluating ‘lunches.push’)”

so I kept changing

---

<div class="post-metadata">

**Author:** ![pkdvalis](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pkdvalis/32/350571_2.png) [@pkdvalis](https://forum.freecodecamp.org/u/pkdvalis)\
**Post date:** [February 20, 2026, 12:09pm UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467/4 "2026-02-20T12:09:33Z")

</div>

> [@andre.wilson](#):
>
> doesn’t the first topic ask to create a var named lunch and assign it an empty string?

Yes

> [@andre.wilson](#):
>
> doesn’t this mean a global var?

Yes

> [@andre.wilson](#):
>
> and then use it on the functions

I don’t see where it says that in User Story 2

> [@pkdvalis](#):
>
> Add the string to the end of the array.

This certainly refers to the array and the string parameters of the function. If you pass the `lunches` array to the function, then it would be the array.

Please review how function parameters and arguments work and make sure it’s clear  
[https://www.w3schools.com/js/js\_function\_parameters.asp](https://www.w3schools.com/js/js_function_parameters.asp)  
Let us know if you have any questions

---

<div class="post-metadata">

**Author:** ![andre.wilson](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/andre.wilson/32/381994_2.png) [@andre.wilson](https://forum.freecodecamp.org/u/andre.wilson)\
**Post date:** [February 20, 2026, 12:10pm UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467/5 "2026-02-20T12:10:29Z")

</div>

ok ill take a look, sorry for the trouble and thank you!

---

<div class="post-metadata">

**Author:** ![pkdvalis](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pkdvalis/32/350571_2.png) [@pkdvalis](https://forum.freecodecamp.org/u/pkdvalis)\
**Post date:** [February 20, 2026, 12:11pm UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467/6 "2026-02-20T12:11:53Z")

</div>

It’s no trouble that’s what we’re here for

---

<div class="post-metadata">

**Author:** ![andre.wilson](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/andre.wilson/32/381994_2.png) [@andre.wilson](https://forum.freecodecamp.org/u/andre.wilson)\
**Post date:** [February 20, 2026, 3:00pm UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467/7 "2026-02-20T15:00:15Z")

</div>

### Tell us what’s happening:

Why is my output in the end this “Menu items: ,Tacos, “ if I don’t have any items before Tacos, why does it have a comma in the start and in the end, shouldn’t it be “Menu items: Tacos”  
this is the full output:

```auto
Tacos added to the end of the lunch menu.
1
undefined added to the end of the lunch menu.
undefined added to the start of the lunch menu.
No lunches to remove.
Randomly selected lunch: Tacos
Menu items: ,Tacos,

```

Thank you!

### Your code so far

```js
let lunches = [];

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

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

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

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

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

function showLunchMenu(array){
  array = lunches
  if(lunches.length > 0){
    console.log(`Menu items: ${array}`)
  } else if (lunches.length < 0){
    console.log("The menu is empty.")
  }
}

addLunchToEnd();
addLunchToStart();
removeLastLunch();
removeFirstLunch();
getRandomLunch();
showLunchMenu();

```

### Your browser information:

User Agent is: `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.3 Safari/605.1.15`

### Challenge Information:

Build a Lunch Picker Program - Build a Lunch Picker Program

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-v9/lab-lunch-picker-program/build-a-lunch-picker-program)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [February 20, 2026, 3:04pm UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467/8 "2026-02-20T15:04:00Z")

</div>

> [@andre.wilson](#):
>
> ```auto
> addLunchToEnd();
> addLunchToStart();
> removeLastLunch();
> removeFirstLunch();
> getRandomLunch();
> showLunchMenu();
> 
> ```

shouldn’t you pass something to the functions when calling them? you have given a parameter or two to each function

---

<div class="post-metadata">

**Author:** ![andre.wilson](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/andre.wilson/32/381994_2.png) [@andre.wilson](https://forum.freecodecamp.org/u/andre.wilson)\
**Post date:** [February 20, 2026, 3:05pm UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467/9 "2026-02-20T15:05:02Z")

</div>

oh right dummy me, thank you so much

---

<div class="post-metadata">

**Author:** ![andre.wilson](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/andre.wilson/32/381994_2.png) [@andre.wilson](https://forum.freecodecamp.org/u/andre.wilson)\
**Post date:** [February 20, 2026, 3:07pm UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467/10 "2026-02-20T15:07:15Z")

</div>

another question, im having trouble in exercise 5, it asks this “`addLunchToEnd(["Pizza", "Tacos"], "Burger")`should return `["Pizza", "Tacos", "Burger"]`.”

I have this “function addLunchToEnd(array, str){

array = lunches.push(str);

console.log(`${str} added to the end of the lunch menu.`);

return array;

}

console.log(addLunchToEnd(lunches, “Tacos”))

console.log(addLunchToEnd([“Pizza”, “Tacos”], “Burger”))

”

and it only gives me this “Menu items: Tacos,Burger”  
”Tacos added to the end of the lunch menu.  
1  
Burger added to the end of the lunch menu.  
2  
undefined added to the end of the lunch menu."

sorry if its a mess

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [February 20, 2026, 3:08pm UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467/11 "2026-02-20T15:08:33Z")

</div>

> [@andre.wilson](#):
>
> array = lunches.push(str);

now that you are calling the function with arguments, , don’t you think that you should use the arguments? instead of using a global variable like `lunches`?

when you call `addLunchToEnd(["Pizza", "Tacos"], "Burger")`, `["Pizza", "Tacos"]` is not `lunches`

---

<div class="post-metadata">

**Author:** ![andre.wilson](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/andre.wilson/32/381994_2.png) [@andre.wilson](https://forum.freecodecamp.org/u/andre.wilson)\
**Post date:** [February 20, 2026, 3:09pm UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467/12 "2026-02-20T15:09:27Z")

</div>

so basically like this?

“function addLunchToEnd(lunches, str){

lunches.push(str);

console.log(`${str} added to the end of the lunch menu.`);

return lunches;

}”

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [February 20, 2026, 3:09pm UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467/13 "2026-02-20T15:09:43Z")

</div>

> [@andre.wilson](#):
>
> sorry if its a mess

you can make it less of a mess if you format the code in the post

When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (`</>`) to add the backticks.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](https://forum.freecodecamp.org/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks (`) are not single quotes (').

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [February 20, 2026, 3:10pm UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467/14 "2026-02-20T15:10:41Z")

</div>

having a function parameter and a global variable having the same name can be confusing, if you think it’s not confusing for you, then you can use any name for the parameters

---

<div class="post-metadata">

**Author:** ![andre.wilson](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/andre.wilson/32/381994_2.png) [@andre.wilson](https://forum.freecodecamp.org/u/andre.wilson)\
**Post date:** [February 20, 2026, 3:11pm UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467/15 "2026-02-20T15:11:20Z")

</div>

ok ok thank you for the help!

---

<div class="post-metadata">

**Author:** ![andre.wilson](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/andre.wilson/32/381994_2.png) [@andre.wilson](https://forum.freecodecamp.org/u/andre.wilson)\
**Post date:** [February 20, 2026, 3:34pm UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467/16 "2026-02-20T15:34:41Z")

</div>

### Tell us what’s happening:

Im having trouble in finishing exercise 29 and 30, and why is my output being repeat a few times, this is my output ``Menu items: Burger,Sushi,Pizza,Pizza,Tacos,Burger``  
Thank you!

### Your code so far

```js
let lunches = []

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

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

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

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

function getRandomLunch(lunches){
  if(lunches.length == 0){
    console.log('No lunches available.');
  }
  else{
      let randNumber = Math.floor(Math.random() *3);
  let randElement = lunches[randNumber];
    console.log(`Randomly selected lunch: ${randElement}`); 
  }
}
getRandomLunch(["Salad", "Eggs", "Cheese"]);

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

addLunchToEnd(lunches);
addLunchToStart(lunches);
removeLastLunch(lunches);
removeFirstLunch(lunches);
getRandomLunch(lunches);
showLunchMenu(lunches);

```

### Your browser information:

User Agent is: `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.3 Safari/605.1.15`

### Challenge Information:

Build a Lunch Picker Program - Build a Lunch Picker Program

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-v9/lab-lunch-picker-program/build-a-lunch-picker-program)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [February 20, 2026, 3:39pm UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467/17 "2026-02-20T15:39:59Z")

</div>

I merged your topics together, if you need more help with the same challenge please keep writing in the same topic

> [@andre.wilson](#):
>
> this is my output

output of what function?

---

<div class="post-metadata">

**Author:** ![pkdvalis](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pkdvalis/32/350571_2.png) [@pkdvalis](https://forum.freecodecamp.org/u/pkdvalis)\
**Post date:** [February 20, 2026, 3:40pm UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467/18 "2026-02-20T15:40:49Z")

</div>

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

> [@andre.wilson](#):
>
> this is my output `Menu items: Burger,Sushi,Pizza,Pizza,Tacos,Burger`

Can you see the difference of your output and the expected output?

---

<div class="post-metadata">

**Author:** ![andre.wilson](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/andre.wilson/32/381994_2.png) [@andre.wilson](https://forum.freecodecamp.org/u/andre.wilson)\
**Post date:** [February 20, 2026, 3:40pm UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467/19 "2026-02-20T15:40:53Z")

</div>

ye I noticed, thank you.

im talking about the last function “showLunchMenu”

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [February 20, 2026, 3:41pm UTC](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467/20 "2026-02-20T15:41:40Z")

</div>

and you are calling `showLunchMenu` with what array?

[Next page](https://forum.freecodecamp.org/t/build-a-lunch-picker-program-build-a-lunch-picker-program/779467.md?page=2)
