Tell us what’s happening:
My code passes all other checks but the last 2. I think it has to do with the random “undefined” that returns to the console but I can’t for the life of me find where it is coming from. If that’s not it, I don’t know why it’s failing. Please help.
Your code so far
let lunches = [];
function addLunchToEnd(ary, str) {
ary.push(str)
console.log(str + " added to the end of the lunch menu.")
return ary
}
function addLunchToStart(ary, str) {
ary.unshift(str)
console.log(str + " added to the start of the lunch menu.")
return ary
}
function removeLastLunch(ary) {
if (ary.length > 0) {
const item = ary.pop()
console.log(item + " removed from the end of the lunch menu.")
} else {
console.log("No lunches to remove.")
}
return ary
}
function removeFirstLunch(ary) {
if (ary.length > 0) {
const item = ary.shift()
console.log(item + " removed from the start of the lunch menu.")
} else {
console.log("No lunches to remove.")
}
return ary
}
function getRandomLunch(ary) {
if (ary.length > 0) {
const randomItem = ary[Math.floor(Math.random() * ary.length)]
console.log("Randomly selected lunch: " + randomItem)
} else {
console.log("No lunches available.")
}
}
function showLunchMenu(ary) {
if (ary.length > 0) {
console.log("Menu items: " + ary)
} else {
console.log("The menu is empty.")
}
}
console.log(showLunchMenu(["Greens", "Corns", "Beans"]))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36
Challenge Information:
Build a Lunch Picker Program - Build a Lunch Picker Program