Tell us what’s happening:
Bottom 4 lines logs two identical pairs of text but function tests will not pass
function showLunchMenu(arr){
if (arr.length===0){
console.log(“The menu is empty.”)
}else{
for (let i = 0; i < arr.length; i++) {
arr[i] = " " + arr[i]
}
console.log(“Menu items:” + arr)
}
}
showLunchMenu([“Greens”, “Corns”, “Beans”])
console.log(“Menu items: Greens, Corns, Beans”)
showLunchMenu([“Pizza”, “Burger”, “Fries”, “Salad”])
console.log(“Menu items: Pizza, Burger, Fries, Salad”)
Your code so far
const lunches =[]
function addLunchToEnd(arr,string){
arr.push(string)
console.log(string + " added to the end of the lunch menu.")
return arr
}
function addLunchToStart(arr, string){
arr.unshift(string)
console.log(string + " added to the start of the lunch menu.")
return arr
}
function removeLastLunch(arr){
if (arr.length===0){
console.log("No lunches to remove.")
}else{
console.log(arr.pop() + " removed from the end of the lunch menu.")
return arr
}
}
function removeFirstLunch(arr){
if (arr.length===0){
console.log("No lunches to remove.")
}else{
console.log(arr.shift() + " removed from the start of the lunch menu.")
return arr
}
}
function getRandomLunch(arr){
if (arr.length===0){
console.log("No lunches available.")
} else {
const length=arr.length
const index = Math.floor(length*Math.random())
console.log("Randomly selected lunch: " + arr[index])
return arr[index]
}
}
function showLunchMenu(arr){
if (arr.length===0){
console.log("The menu is empty.")
}else{
for (let i = 0; i < arr.length; i++) {
arr[i] = " " + arr[i]
}
console.log("Menu items:" + arr)
}
}
showLunchMenu(["Greens", "Corns", "Beans"])
console.log("Menu items: Greens, Corns, Beans")
showLunchMenu(["Pizza", "Burger", "Fries", "Salad"])
console.log("Menu items: 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/148.0.0.0 Safari/537.36
Challenge Information:
Build a Lunch Picker Program - Build a Lunch Picker Program