Tell us what’s happening:
I cannot pass test 24 no matter what I do even though it has the correct output.
Your code so far
const lunches = []
function addLunchToEnd(arr, str) {
arr.push(str)
console.log(`${str} added to the end of the lunch menu.`)
return arr
}
function addLunchToStart(arr, str) {
arr.unshift(str)
console.log(`${str} added to the start of the lunch menu.`)
return arr
}
function removeLastLunch(arr) {
const arrayLength = arr.length
const itemNum = arrayLength - 1
const itemRemoved = arr[itemNum]
arr.pop()
if (arrayLength == 0) {
console.log("No lunches to remove.")
} else {
console.log(`${itemRemoved} removed from the end of the lunch menu.`)
}
return arr
}
function removeFirstLunch(arr) {
const arrayLength = arr.length
const itemRemoved = arr[0]
arr.shift()
if (arrayLength == 0) {
console.log("No lunches to remove.")
} else {
console.log(`${itemRemoved} removed from the start of the lunch menu.`)
}
return arr
}
function getRandomLunch(arr) {
const arrayLength = arr.length
const min = 1
const max = arrayLength
const num = Math.floor(Math.random() * (max-min) + min)
if (arrayLength == 0) {
console.log("No lunches available.")
} else {
console.log("Randomly selected lunch: " + arr[num])
}
}
function showLunchMenu(arr) {
const arrayLength = arr.length
const start = arr.length - 1
const lunch1 = arr[start - 3]
const lunch2 = arr[start - 2]
const lunch3 = arr[start - 1]
const lunch4 = arr[start]
if (arrayLength == 0) {
console.log("The menu is empty.")
} else if (lunch1 == undefined) {
console.log(`Menu items: ${lunch2}, ${lunch3}, ${lunch4}`)
} else {
console.log(`Menu items: ${lunch1}, ${lunch2}, ${lunch3}, ${lunch4}`)
}
}
console.log(getRandomLunch(["Pizza", "Fries", "Salad"]))
Your browser information:
User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Challenge Information:
Build a Lunch Picker Program - Build a Lunch Picker Program