Tell us what’s happening:
Hi. I’m really struggling to know why I can’t pass any of the log to console tests for my first four functions. I’m passing all other tests and just can’t see what’s wrong with those console.log() statements. Any help would be very much appreciated.
Your code so far
const lunches = [];
function addLunchToEnd(lunches, lunchItem) {
lunches.push(lunchItem);
console.log(`${lunchItem} added to the end of the lunch menu.`);
console.log(lunches);
return lunches;
}
function addLunchToStart(lunches, lunchItem) {
lunches.unshift(lunchItem);
console.log(`${lunchItem} added to the start of the lunch menu.`);
console.log(lunches);
return lunches;
}
function removeLastLunch(lunches) {
if (lunches.length === 0) {
console.log("No lunches to remove.");
} else {
const poppedLunch = lunches.pop();
console.log(`${poppedLunch} removed from the end of the lunch menu.`);
}
console.log(lunches);
return lunches;
}
function removeFirstLunch(lunches) {
if (lunches.length === 0) {
console.log("No lunches to remove.");
} else {
const shiftedLunch = lunches.shift();
console.log(`${shiftedLunch} removed from the start of the lunch menu.`);
}
console.log(lunches);
return lunches;
}
function getRandomLunch(lunches) {
const randomLunch = lunches[Math.floor(Math.random() * lunches.length)];
if (lunches.length > 0) {
console.log(`Randomly selected lunch: ${randomLunch}`);
} else {
console.log(`No lunches available.`);
return randomLunch
}
}
function showLunchMenu(lunches) {
if (lunches.length > 0) {
console.log("Menu items: " + lunches.join(", "));
} 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/133.0.0.0 Safari/537.36
Challenge Information:
Build a Lunch Picker Program - Build a Lunch Picker Program