我正在尝试练习一门课程,但我被this step困住了。我不知道问题出在哪里了?
var todoList = {
todos: [],
displayTodo: function() {
if (this.todos.length === 0) {
console.log('todos are empty')
} else {
console.log("my todos: ");
for (i = 0; i < this.todos.length; i++) { // i think the problem is into this for loop
if (this.todos[i].complited === true) {
console.log("(X) " + this.todos[i].todoText);
} else {
console.log("( ) " + this.todos[i].todoText);
}
}
}
},
addTodo: function(todoText) {
this.todos.push({
todoText: todoText,
completed: false
});
this.displayTodo();
},
changeTodo: function(index, newValue) {
this.todos[index].Text = newValue;
this.displayTodo();
},
deletTodo: function(position) {
this.todos.splice(position, 1);
this.displayTodo();
},
toggelComplited: function(position) // this i working correctly
{
var todo = this.todos[position];
todo.completed = !todo.completed;
this.displayTodo();
}
};
&#13;
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<h1>Hello bilal!</h1>
</body>
</html>
&#13;
这是我在我的控制台中看到的(看下面的评论==&gt; //....):
todoList.displayTodo()
&LT; todos是空的
todoList.addTodo(&#34;第一&#34)
&LT;我的待办事项: &LT; ()首先
todoList.addTodo(&#34;第二&#34)
&LT;我的待办事项:
&LT; ()首先
&LT; ()第二次
todoList.todos [0]
&LT; {todoText:&#34; first&#34;,completed:false}
todoList.todos [1]
&LT; {todoText:&#34; second&#34;,completed:false}
todoList.toggelComplited(0)
&LT;我的待办事项:
&LT; ()首先//这一行应该告诉我:(X)第一个
&LT; ()第二次
答案 0 :(得分:1)
看起来像是#34;完成&#34;在for循环中
if (this.todos[i].**complited** === true) {