我只是从这里开始使用Javascript,并创建了一个简单的待办事项列表
下面的代码可以正常工作,但是直到执行结束(当我输入“退出”时),我才能看到控制台消息或网页
<!DOCTYPE html>
<html>
<head>
<title>Todo list</title>
<script type="text/javascript" src="Magic.js"></script>
</head>
<body>
<h1>Todo list</h1>
<ul>
<li>new - to add to list</li>
<li>list - to show the list</li>
<li>delete - to delete an item</li>
<li>quit - to quit the list</li>
</ul>
</body>
<script type="text/javascript" src="Magic.js"></script>
</html>
这是html,下面是java脚本
console.log("CONNECTED!!!");
alert("CONNECTED");
var input = prompt("What do you wanna do??");
var todoList = ["Groccery"];
while(input!=="quit")
{
if(input === "new")
{
addTodo();
}
else if(input === "list")
{
listTodo();
}
else if(input === "delete")
{
deleteTodo();
}
input = prompt("what do you wanna do next");
}
console.log("OKK YOU QUIT");
function addTodo()
{
newItem = prompt("Enter the item to be added");
todoList.push(newItem);
console.log("Item Added!");
}
function listTodo()
{
console.log("*****************");
todoList.forEach(function(todo , i){
console.log(i + ": " + todo);
})
console.log("*****************");
}
function deleteTodo()
{
index = prompt("Enter the index of the Item to be deleted ");
todoList.splice(index , 1);
}
connected as alert but nothing in console
Listing but nothing in console
at the end the html is loaded and also i see everything in console as it should be