Tell us what’s happening:
Help me with this. My removeLastLunch function is showing this error: TypeError: Cannot read proerties of undefined (reading ‘length’).
Your code so far
const lunches = [];
const addLunchToEnd = (lunches, str) => {
let newArr = lunches.push(str);
console.log(`${str} added to the end of the lunch menu.`);
return lunches;
}
console.log(addLunchToEnd(lunches,"Tacos"));
addLunchToEnd(["Pizza", "Tacos"],"Burger");
const addLunchToStart = (lunches,str) => {
let newArr = lunches.unshift(str);
console.log(`${str} added to the start of the lunch menu.`);
return lunches;
}
console.log(addLunchToStart(lunches, "Sushi"));
let result = addLunchToStart(["Burger","Sushi"],"Pizza");
console.log(result);
const removeLastLunch = (lunches) => {
if (lunches.length!==1){
let newArray = lunches.pop();
console.log(`${newArray} removed from the end of the lunch menu.`);
}else{
console.log("No lunches to remove.");
}
return lunches;
}
removeLastLunch();
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0
Challenge Information:
Build a Lunch Picker Program - Build a Lunch Picker Program