Tell us what’s happening:
Hi!! I cannot pass test 23 and 24:
23. When the input array is empty, the function getRandomLunch should log the string “No lunches available.” to the console.
24. When the input array is not empty, the function getRandomLunch should log a string in the format Randomly selected lunch: [Lunch Item] to the console.
Idk what to put as the return statement. I have tried to put the array as the return but it still doesn’t pass
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;
};
console.log(addLunchToEnd(lunches, "Salad"));
console.log(addLunchToEnd(lunches, "Eggs") );
console.log(addLunchToEnd(lunches, "Cheese"));
function removeLastLunch(arr){
const last = arr.pop();
if(`${last}`=== undefined){
console.log("No lunches to remove.");
}else if(arr.length === 0){
console.log("No lunches to remove.")
}else{
console.log(`${last} removed from the end of the lunch menu.`);
}
return arr;
};
function removeFirstLunch(arr){
const first = arr.shift();
if(`${first}` === undefined){
console.log("No lunches to remove.");
}else if(arr.length === 0){
console.log("No lunches to remove.");
}else{
console.log(`${first} removed from the start of the lunch menu.`)
}
return arr;
};
function getRandomLunch(arr){
const randomLunch = Math.floor(Math.random() * arr.length);
const selected = lunches[randomLunch];
if (lunches.length === 0){
console.log("No lunches available.");
}else{
console.log(`Randomly selected lunch: ${selected}`);
}
}
console.log(removeFirstLunch(lunches));
console.log(getRandomLunch(lunches));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Challenge Information:
Build a Lunch Picker Program - Build a Lunch Picker Program