创建午餐选择程序 - 创建一个午餐选择程序

告诉我们发生了什么:

  1. 要求将([“Stew”,“Soup”,"Toast”,])输了进函数removeLastLunch并记录下来,我函数写好了然后测试这一环节removeLastLunch(这里也不能写东西),不然第1.lunches是用来诸存的空数组。要求就不对了

你目前的代码

const lunches = [];

function addLunchToEnd(lunches,string){
  lunches.push(string)
  console.log(string + " added to the end of the lunch menu.");

  return lunches;
}

addLunchToEnd(lunches,"Pizza");
addLunchToEnd(lunches,"Tacos");
addLunchToEnd(lunches,"burger");

console.log(lunches);

function addLunchToStart(lunches,string){
  lunches.unshift(string);
  console.log(string + " added to the start of the lunch menu.")

  return lunches;
}

addLunchToStart(lunches,"Sushi")

console.log(lunches);

function removeLastLunch(lunches){
  if(lunches.length === 0){
    console.log("No lunches to remove.");
  }else {
    const removeLast = lunches.pop();
    console.log(removeLast + " remove from the start of the lunch menu.");
  }
  return lunches;
}
removeLastLunch

console.log(lunches);

你的浏览器信息:

用户代理是:Mozilla/5.0 (iPhone; CPU iPhone OS 26_6_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/154.0.8037.55 Mobile/15E148 Safari/604.1

挑战信息:

创建午餐选择程序 - 创建一个午餐选择程序

GitHub 链接:i18n-curriculum/curriculum/challenges/chinese/blocks/lab-lunch-picker-program/66db529d37ad966480ebb633.md at main · freeCodeCamp/i18n-curriculum · GitHub

Hi @Laukkvan,

Is this the message you are asked to return?

Try testing your function to see what it returns:

console.log(removeLastLunch(["Stew", "Soup", "Toast"]));

Happy coding

很谢谢你,但13.它还是不通过我将你的建议拭了

在函数外进行console.log(removeLastLunch([…));

它显示我的句子并没有记录下来。

我的疑问就是const lunches =[];储存的空数组,

13. 的函数完成后,我要测试

removeLastLunch(lunches)这里的lunches写了字符就会给开头的数组进行定义,就会冲突我应该怎么修

You are not testing your function as asked. The function definition has a lunches parameter, but you can pass any array to it that represents lunches.

The only reason you are creating an empty lunches array is so you have it available for use in addLunchToStart and addLunchToEnd.