Hi, the test 28 is not passed. why the out put is true
Your code so far
let lunches=[];
function addLunchToEnd(lunches,mys){
lunches.push(mys);
console.log(`${mys} added to the end of the lunch menu.`);
return lunches;
}
addLunchToEnd(lunches,["Pizza", "Tacos", "Burger"]);
function addLunchToStart(lunches,mys){
lunches.unshift(mys);
console.log(`${mys} added to the start of the lunch menu.`);
return lunches;
}
addLunchToStart(lunches,["Burger", "Sushi", "Pizza"]);
function removeLastLunch(lunches){
if(lunches.length!==0){
let popedLunch= lunches.pop();
console.log(`${popedLunch} removed from the end of the lunch menu.`);
}
else{
console.log("No lunches to remove.");
}
return lunches;
}
removeLastLunch(["Stew", "Soup", "Toast"]);
function removeFirstLunch(lunches){
if(lunches.length!=0){
let removedItem=lunches.shift();
console.log(`${removedItem} removed from the start of the lunch menu.`)
}
else{
console.log("No lunches to remove.");
}
return lunches;
}
removeFirstLunch(["Salad", "Eggs", "Cheese"]);
//get Random Lunch function:
function getRandomLunch(lunches){
if(lunches.length==0){
console.log('No lunches available.');
}
else{
let randNumber=Math.floor(Math.random() *3);
let randElement=lunches[randNumber];
console.log(`Randomly selected lunch: ${randElement}`);
}
}
getRandomLunch(["Salad", "Eggs", "Cheese"]);
// funation show Lunch Menu
function showLunchMenu(lunches){
if(lunches.length!=0){
console.log(`Menu items:${lunches}`);
}
else{
console.log('The menu is empty.');
}
}
//showLunchMenu([]);
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/131.0.0.0 Safari/537.36
Challenge Information:
Build a Lunch Picker Program - Build a Lunch Picker Program
to the console. // tests completed // console output Pizza,Tacos,Burger added to the end of the lunch menu. Burger,Sushi,Pizza added to the start of the lunch menu. Toast removed from the end of the lunch menu. Salad removed from the start of the lunch menu. Randomly selected lunch: Cheese Menu items:Greens,Corns,Beans
yes it passed , the last edited form of showLunchMenu function is as follow
// funation show Lunch Menu
function showLunchMenu(lunches){
let [l1,l2,l3,...rest] = lunches
if(lunches.length!=0){
console.log(`Menu items: ${l1}, ${l2}, ${l3}`);
}
else{
console.log('The menu is empty.');
}
}
showLunchMenu(["Greens", "Corns", "Beans"]);
I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
function showLunchMenu(lunches){
let [l1,l2,...rest] = lunches
if(lunches.length!=0){
console.log(`Menu items: ${l1}, ${l2}, ${rest}`);
}
else{
console.log('The menu is empty.');
}
}
showLunchMenu(["Greens", "Corns", "Beans"]);```
if there were mor elements we will use rest operator as shown in the code.
If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Get Help > Ask for Help button located on the challenge.
The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.