Tell us what’s happening:
I am having trouble with step 29 of building a lunch picker. I do not recall how to display the output of the lunches array in a specific order other than logging just the array to console. My showlunchmenu function is not doing what its supposed to.
Your code so far
let lunches = [];
const addLunchToEnd = (arr, str) => {
arr.push(str);
console.log(`${str} added to the end of the lunch menu.`);
return arr;
}
const addLunchToStart = (arr, str) => {
arr.unshift(str);
console.log(`${str} added to the start of the lunch menu.`);
return arr;
}
const removeLastLunch = (arr) => {
if (arr.length === 0) {
console.log("No lunches to remove.");
return arr;
}
let item = arr.pop();
console.log(`${item} removed from the end of the lunch menu.`);
return arr;
}
const removeFirstLunch = (arr) => {
if (arr.length === 0) {
console.log("No lunches to remove.");
return arr;
} else {
let item = arr.shift();
console.log(`${item} removed from the start of the lunch menu.`);
return arr;
}
}
const getRandomLunch = (arr) => {
if (arr.length === 0) {
console.log("No lunches available.");
return arr;
} else {
let randomIndex = Math.round(Math.random() * (arr.length - 0) + 0);
let lunch = arr[randomIndex];
console.log(`Randomly selected lunch: ${lunch}`);
return lunch;
}
}
const showLunchMenu = (arr) => {
if (arr.length > 0) {
let [first, second, third] = arr;
console.log(`Menu items: ${first}, ${second}, ${third}`)
}
else {
console.log("The menu is empty.")
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Challenge Information:
Build a Lunch Picker Program - Build a Lunch Picker Program