javascript - 在 JS 中调试 ToDoList 类型的任务
问题描述
我正在尝试制作一个在控制台中运行并带有提示的 todolist 类型的任务。
它的想法如下: 提示显示,您可以键入以下操作之一:新项目/删除项目/列出项目/退出。
问题是,例如,当我键入“new”然后“return”(完成列表后)然后对于 ex,我键入“list”(控制台显示列表数组),但是当我想再次键入“new”(添加adional items) ,任务关闭。
我看不出我在代码中是否错了......为什么当我输入“new”时“new”while循环没有第二次启动?
这是我目前拥有的代码:
let input = prompt("Welcome to TO-DO-LIST! Please chose an action : 1. Add item - type 'new' / 2. List all todos - type 'list' / 3. Remove a specific todo - type 'delete' / 4. Quit - type 'quit'")
const list = [];
// NEW ITEMS FUNCTION
while (input === 'new'){
let item = prompt("What would you like to do? Type 'return' to go back to main menu");
if(item === 'return'){
input = prompt("Welcome to TO-DO-LIST! Please chose an action : 1. Add item - type 'new' / 2. List all todos - type 'list' / 3. Remove a specific todo - type 'delete' / 4. Quit - type 'quit'")
}else{
list.push(item);
}
}
// REMOVE ITEMS FUNCTION
while(input ==='delete'){
let removeItem = prompt("What would you like to remove? Type 'return' to go back to main menu")
if(removeItem === 'return'){
input = prompt("Welcome to TO-DO-LIST! Please chose an action : 1. Add item - type 'new' / 2. List all todos - type 'list' / 3. Remove a specific todo - type 'delete' / 4. Quit - type 'quit'")
}else{
list.splice(0, 1, removeItem);
}
}
// QUIT FUNCTION
if(input==='quit'){
console.log("You have exited the list");
}
// SHOW LIST FUNCTION
while(input ==='list'){
console.log('---------');
for(let i = 0; i < list.length; i++){
console.log(`${i}: ${list[i]}`);
}
console.log('---------');
input = prompt("Welcome to TO-DO-LIST! Please chose an action : 1. Add item - type 'new' / 2. List all todos - type 'list' / 3. Remove a specific todo - type 'delete' / 4. Quit - type 'quit'")
}
解决方案
推荐阅读
- powershell - 使用 PowerShell 为文件夹中的所有文件创建 App Locker 规则/策略
- javascript - history.pushState 和 history.back 逻辑错误
- flutter - Dart - 单击飞镖后如何更改我的 raiseButton 的颜色?
- python - 使用和不使用随机播放的 sklearn KFold 之间的区别
- python - Gmail附件未从python程序下载
- java - Java Regex 获取所有数字
- google-bigquery - 是否可以在 AWS S3 上的镶木地板文件上编写/运行 BigQuery?
- sql-server - 在 Windows 容器中运行的 Windows Server Core 2019 上的 SQL Server 2012 设置失败
- python - 动态调用python方法
- c# - Enviroment.GetCommandLineArgs()[0] 是一个 .exe 文件的 .dll 文件