Build a Lunch Picker Program - Build a Lunch Picker Program

Tell us what’s happening:

I need help in passing 23, 24, 29,30. Any help is appreciated.

Your code so far

let lunches = []
function addLunchToEnd(array,word){
  array.push(word)
  console.log(`${word} added to the end of the lunch menu.`)
  return array
}

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

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

function removeFirstLunch(array){
  let addedValue = array.shift();
if(array.length === 0){
    console.log("No lunches to remove.")
  }else{
  console.log(`${addedValue} removed from the start of the lunch menu.`);
  }
  return array;
}
function getRandomLunch(array){
  let randomArray = array[getRandomInt(0,array.length)];
  if(randomArray){
    console.log(`Randomly selected lunch: ${randomArray}`)
  }
  if(randomArray === 0){
    console.log("No lunches available.")
  }
}

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


function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

Your browser information:

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

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 @daiwik

To help you debug, add the following code at the botton of the editor:

console.log(getRandomLunch(lunches))

Happy coding

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

Why am i getting output Menu items: Pizza,Burger,Fries,Salad
undefined
Where is this undefined coming from

What does showLunchMenu return?

Happy coding

It returns

Menu items: Pizza,Burger,Fries,Salad

undefined

let’s try again, what is the return statement inside showLunchMenu?

it returns nothing, it just logs the output

function showLunchMenu(array){

if(array.length === 0){

console.log("The menu is empty.")

}else{

console.log(`Menu items: ${array}`);

}

}

a function always returns something, so if it doesn’t have a return statement, what does it return? what’s the default?

undefined, so what should i do so it doesnt return undefined. i tried return “” but it outputs one line

it’s the answer to this

for this instead, is the expected output like that, no spaces?

i used join(", ") and it passed that test

function getRandomLunch(array){

let randomArray = array[getRandomInt(0,array.length)];

if(randomArray){

console.log(`Randomly selected lunch: ${randomArray}`)

}

if(array.length === 0){

console.log("No lunches available.")

}

return “”

}

console.log(getRandomLunch([“Pizza”, “Burger”, “Fries”, “Salad”]))

function getRandomInt(min, max) {

return Math.floor(Math.random() * (max - min + 1)) + min;

}

I dont get why this is not passing when the output is right

The output I got:

Randomly selected lunch: Burger

i solved it by adding -1 to array.length()

good problem solving there!