Tell us what’s happening:
Ive already met all the outputs in the console but test 28,29 doesnt pass whats wrong with my code.
Your code so far
let lunches = [];
function addLunchToEnd(array,item){
array.push(item);
console.log(item+" added to the end of the lunch menu.");
return array;
}
function addLunchToStart(array,item){
array.unshift(item);
console.log(item + " added to the start of the lunch menu.");
return array;
}
function removeLastLunch(array){
if (array.length === 0 ){
console.log("No lunches to remove.");
} else {
const removed = array.pop();
console.log(removed + " removed from the end of the lunch menu.");
}
return array;
}
function removeFirstLunch(array){
if(array.length === 0 ){
console.log("No lunches to remove.");
} else{
const removed = array.shift();
console.log(removed + " removed from the start of the lunch menu.");
}
return array;
}
function getRandomLunch(array){
if(array.length === 0 ){
console.log("No lunches available.");
}else {
const randomIndex = Math.floor(Math.random() * array.length);
const randomLunch = array[randomIndex];
console.log("Randomly selected lunch: " + randomLunch)
}
}
function showLunchMenu(array){
if (array.length === 0 ){
console.log("The menu is empty.");
} else {
console.log(`"Menu items: ` + array.join(", ") + `"`);
}
}
addLunchToEnd(lunches, "Tacos");
addLunchToStart(["Burger", "Sushi"], "Pizza");
removeLastLunch(["Stew", "Soup", "Toast"]);
removeFirstLunch(["Salad", "Eggs", "Cheese"]);
removeFirstLunch(["Sushi", "Pizza", "Burger"]);
showLunchMenu(["Greens", "Corns", "Beans"]);
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/136.0.0.0 Safari/537.36
Challenge Information:
Build a Lunch Picker Program - Build a Lunch Picker Program