Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDavid Drysdale
10,815 PointsAppends don't appear to be working
I was moving along fine until we got to the point where completed items are being moved to the completed tasks list. I've gone back through the video but I can't seem to identify what the issue is.
(As an side, it'd be nice if there were a way to view the instructor's source code at the end of each video.)
EDIT: Found it: typo in the declaration of completedTasksHolder (below I have "complete-tasks" instead of "completed-tasks")!
//Problem: User interaction does not provide desired results.
//Solution:Add interactivity so the user can accomplish daily tasks
var taskInput = document.getElementById("new-task"); //new-task
var addButton = document.getElementsByTagName("button")[0]; //first button on the page
var incompleteTasksHolder = document.getElementById("incomplete-tasks"); //incomplete-tasks
var completedTasksHolder = document.getElementById("complete-tasks"); //completed-tasks
var createNewTaskElement = function(taskString) {
//create list item
var listItem = document.createElement("li");
//input (checkbox)
var checkBox = document.createElement("input"); // checkbox
//label
var label = document.createElement("label");
//input (text)
var editInput = document.createElement("input");
//button.edit
var editButton = document.createElement("button");
//button.delete
var deleteButton = document.createElement("button");
//Each element needs modified
// and each element needs appended
listItem.appendChild(checkBox);
listItem.appendChild(label);
listItem.appendChild(editInput);
listItem.appendChild(editButton);
listItem.appendChild(deleteButton);
return listItem;
}
//Add a new task
var addTask = function() {
console.log("add task...");
//Create a task: add a new <li> to <ul class="incomplete-tasks">
var listItem = createNewTaskElement("Some New Task");
//Append listeItem to incompleteTasksHolder;
incompleteTasksHolder.appendChild(listItem);
}
//Edit an existing task
var editTask = function() {
//When the edit button is pressed
console.log("Edit task...");
//If the class of the parent is .editMode
//switch from .editMode
//make label text become the input's value
//else
//switch to editMode
//input value becomes the label's text
//toggle /editMode
}
//Delete an existing task
var deleteTask = function(){
console.log("delete task...");
//When the delete button is pressed,
//remove the parent list item from the ul
}
//Mark a task as complete
var taskCompleted = function(){
console.log("task complete...");listItem
//append the task list item to the #completed-tasks
var listItem = this.parentNode;
completedTasksHolder.appendChild(listItem);
}
//Mark a task as incomplete
var taskIncomplete = function() {
console.log("task incomplete");
//when the checkbox is unchecked
var listItem = this.parentNode;
incompleteTasksHolder.appendChild(listItem);
//append the task list item to the #incomplete-tasks
}
var bindTaskEvents = function(taskListItem, checkBoxEventHandler) {
console.log("Bind list item events");
//select taskListItem's children
var checkBox = taskListItem.querySelector("input[type=checkbox]");
var editButton = taskListItem.querySelector("button.edit");
var deleteButton = taskListItem.querySelector("button.delete");
//bind editTask to edit button
editButton.onclick = editTask;
//bind deleteTask to delete button
deleteButton.onclick = deleteTask;
//bind checkBoxEventHandler to the checkbox
checkBox.onchange = checkBoxEventHandler;
}
//Set the click handler to the addTask function
addButton.onclick = addTask;
//Cycle over the incompleteTasksHolder ul list items
for(var i = 0; i < incompleteTasksHolder.children.length; i++) {
//bind events to list item's children (taskCompleted)
bindTaskEvents(incompleteTasksHolder.children[i], taskCompleted);
}
//Cycle over the completedTasksHolder ul list items
for(var i = 0; i < completedTasksHolder.children.length; i++) {
bindTaskEvents(completedTasksHolder.children[i], taskIncomplete);
}
Joel Brennan
18,300 PointsGlad you solved it. On a side note, the instructors code can be viewed from the project downloads.
Sherly Chan
7,250 PointsSherly Chan
7,250 Pointsthis part would be covered in later video - Perform : Modifying Elements.