【问题标题】:why is console.log not working with this code(i am not console.log (ging) infinitely)为什么console.log不能使用这个代码(我不是console.log(ging)无限)
【发布时间】:2021-03-06 12:49:03
【问题描述】:

这是一个简单的 cli(控制台行界面)待办事项应用程序的代码 但是当这段代码运行时 console.log 不起作用 我只在chrome中试过

let todos = [];
let user_input = 0;
while (user_input !== "quit") {
    user_input = prompt("what would you like to do?");
    if (user_input === "new") {
        todos.push(prompt("what will be the todo"));
        console.log("bruh");
    } else if (user_input === "list") {
        for (let i = 0; i <= todos.length - 1; i++) {
            console.log(`${i + 1}: ${todos[i]}`);
        }
    } else if (user_input === "delete") {
        let index = parseInt(
            prompt("what is the index of item you want to delete")
        );
        todos.splice(index, 1);
        for (let i = 0; i <= todos.length - 1; i++) {
            console.log(`${i + 1}: ${todos[i]}`);
        }
    }
}
console.log("thanks for using me");

我是初学者 对不起,如果这是个愚蠢的问题 提前谢谢

【问题讨论】:

  • 在 Firefox 和 Chrome 中为我工作。您究竟是如何尝试使用该代码的?
  • @pointy 你能看到console.log吗?
  • @Pointy while 循环中的每个 console.log 都不会显示在控制台中
  • 打开你的控制台并输入console.log("hello world")。这行得通吗?

标签: javascript google-chrome


【解决方案1】:

转到开发人员工具中的控制台选项卡并检查是否在标签下拉菜单下选择了信息

【讨论】:

  • 什么信息?________
  • 这应该是一条评论,因为它没有提供答案。
  • 好吧,你能给我一个更大的截图吗?我看不到这个选项在哪里
  • 我的日志级别默认是锁定的,是灰色的
【解决方案2】:

您只需将“while”更改为“if”即可:)

【讨论】:

  • 这是不正确的;代码已经可以工作了。
  • 实际上是正确的,while 循环不会让你到达 console.log 所以如果你像我说的那样改变它应该可以工作,是的有点晚回复大声笑,但仍然。无论如何,如果有人愿意纠正我,那就这样做吧。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-02-03
  • 1970-01-01
  • 2022-01-08
  • 2014-08-02
  • 1970-01-01
  • 1970-01-01
  • 2021-10-30
相关资源
最近更新 更多