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 trial

JavaScript Interactive Web Pages with JavaScript Traversing and Manipulating the DOM with JavaScript Perform: Modifying Elements

Nothing works at ALL on my js. Firefox, Google, Edge

https://w.trhou.se/8h2jchx3az

JS

//Problem: User interaction doesn't provide desired results.
//Solution: Add interactivity so the user can manage daily tasks.

var taskInput = document.getElementById("new-task"); //new-task
var addButton = document.getElementsByTagName("button")[0]; //first button
var incompleteTasksHolder = document.getElementById("incomplete-tasks"); //inocmplete-tasks ul
var completedTasksHolder = document.getElementById("completed-tasks"); //Completedtasks

//New Task List Item
var createNewTaskElement = function(taskString) {
  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"); //text
  //button.edit
  var editButton = document.createElement("button");
  //button.delete
  var deleteButton = document.createElement("button");

    //Each elements needs modifying
  checkBox.type = "checkbox";
  editInput.type = "text";

  editButton.innerHTML = "Edit";
  editButton.className = "edit";
  deleteButton.innerText= "Delete";
  deleteButton.className = "delete";

  label.innerText = taskString;
    //Each element needs appending
  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 a new list item with the text from #new-task:
  var listItem = createNewTaskElement(taskInput.value);

  //Append listItem to incompleteTasksHolder
  incompleteTasksHolder.appendChild(listItem);
   bindTaskEvents(listItem, taskCompleted);
}

//Edit an existing task
var editTask = function() {
  console.log("Edit task...");
  //When the Edit button is pressed

  var listItem = this.parentNode;

  var editInput = listItem.querySelector("input(type=text)");
  var label = listItem.querySelector("label");
       //Toggle .editMode on the parent
  listItem.classList.toggle("editMode"); 
  var containsClass = listItem.classList.contains("editMode");
    //if the class of the parent is in .editMode
    if(containsClass) {
      //Switch from .editMode
      //label text become the input's value
      label.innerText = editInput.value;
    } 
    else {
      //Switch to .editMode
      //input value becomes the label's text
      editInput.value = label.innerText;
}

//Delete an existing task
var deleteTask = function() { 
    console.log("Delete task...");
    var listItem = this.parentNode;
    var ul = listItem.parentNode;

    //Remove the parent list item from the ul
    ul.removeChild(listItem);
}

//Mark a task as complete
var taskCompleted = function() {
    console.log("Task complete...");
    //Append the task list item to the #completed-tasks
    var listItem = this.parentNode;
    completedTasksHolder.appendChild(listItem);
   bindTaskEvents(listItem, taskInComplete);
}

//Mark a task as incomplete
var taskIncomplete = function() {
  console.log("Task incomplete...");
  //Append the task list item to the #incompleted-tasks
  var listItem = this.parentNode;
  incompleteTasksHolder.appendChild(listItem);
  bindTaskEvents(listItem, taskCompleted);
}
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 the editTask to edit button
    editButton.onclick = editTask;

    //bind deleteTask to delete button
    deleteButton.onclick = deleteTask;

    //bind taskCompleted to checkbox
    checkBox.onchange = checkBoxEventHandler; 
  }

  //Set the click handler to the addTask Function
  addButton.onclick = addTask;

  //cycle over incompleteTasksHolder ul list items
    for(var i = 0; i < incompleteTasksHolder.children.length; i +=1) {

      //bind events to list items's childeren (taskCompleted)
      bindTaskEvents(incompleteTasksHolder.children[i], taskCompleted);

 }

  //cycle over completeTasksHolder ul list items
    for(var i = 0; i < completeTasksHolder.children.length; i +=1) {
      //bind events to list items's childeren (taskIncomplete)
      bindTaskEvents(completeTasksHolder.children[i], taskIncomplete);
 }
LaVaughn Haynes
LaVaughn Haynes
12,397 Points

I edited your question to display the code correctly. Click Markdown Cheatsheet below the quesiton/comment text fields to see how to do it (uses 3 ticks)

2 Answers

LaVaughn Haynes
LaVaughn Haynes
12,397 Points

You had a few errors in your code. This fixes a lot of them. You will still need to fix your editTask function because it's not going to save your edits as it is. My edits have "**************" next to them

//Problem: User interaction doesn't provide desired results.
//Solution: Add interactivity so the user can manage daily tasks.

var taskInput = document.getElementById("new-task"); //new-task
var addButton = document.getElementsByTagName("button")[0]; //first button
var incompleteTasksHolder = document.getElementById("incomplete-tasks"); //inocmplete-tasks ul
var completedTasksHolder = document.getElementById("completed-tasks"); //Completedtasks

//New Task List Item
var createNewTaskElement = function(taskString) {
  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"); //text
  //button.edit
  var editButton = document.createElement("button");
  //button.delete
  var deleteButton = document.createElement("button");

  //Each elements needs modifying
  checkBox.type = "checkbox";
  editInput.type = "text";

  editButton.innerHTML = "Edit";
  editButton.className = "edit";
  deleteButton.innerText= "Delete";
  deleteButton.className = "delete";

  label.innerText = taskString;

  //Each element needs appending
  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 a new list item with the text from #new-task:
  var listItem = createNewTaskElement(taskInput.value);

  //Append listItem to incompleteTasksHolder
  incompleteTasksHolder.appendChild(listItem);
   bindTaskEvents(listItem, taskCompleted);
}

//Edit an existing task
var editTask = function() {
  console.log("Edit task...");
  //When the Edit button is pressed

  var listItem = this.parentNode;

  //Error: bad querySelector.  "input(type=text)" should be "input[type=text]" ********************
  var editInput = listItem.querySelector("input[type=text]");
  var label = listItem.querySelector("label");

  //Toggle .editMode on the parent
  listItem.classList.toggle("editMode"); 
  var containsClass = listItem.classList.contains("editMode");

  //if the class of the parent is in .editMode
  if(containsClass) {
    //Switch from .editMode
    //label text become the input's value
    label.innerText = editInput.value;
  } 
  else {
    //Switch to .editMode
    //input value becomes the label's text
    editInput.value = label.innerText;
  }//missing closing bracket *****************

}

//Delete an existing task
var deleteTask = function() { 
  console.log("Delete task...");
  var listItem = this.parentNode;
  var ul = listItem.parentNode;

  //Remove the parent list item from the ul
  ul.removeChild(listItem);
}

//Mark a task as complete
var taskCompleted = function() {
    console.log("Task complete...");
    //Append the task list item to the #completed-tasks
    var listItem = this.parentNode;
    completedTasksHolder.appendChild(listItem);
    //typo. taskInComplete should be taskIncomplete *******************
    bindTaskEvents(listItem, taskIncomplete);
}

//Mark a task as incomplete
var taskIncomplete = function() {
  console.log("Task incomplete...");
  //Append the task list item to the #incompleted-tasks
  var listItem = this.parentNode;
  incompleteTasksHolder.appendChild(listItem);
  bindTaskEvents(listItem, taskCompleted);
}

var bindTaskEvents = function(taskListItem, checkBoxEventHandler) {
  console.log("Bind list item events");//missing semicolon *************
  //select taskListItem's children
  var checkBox = taskListItem.querySelector("input[type='checkbox']");
  var editButton = taskListItem.querySelector("button.edit");
  var deleteButton = taskListItem.querySelector("button.delete");

  //bind the editTask to edit button
  editButton.onclick = editTask;

  //bind deleteTask to delete button
  deleteButton.onclick = deleteTask;

  //bind taskCompleted to checkbox
  checkBox.onchange = checkBoxEventHandler; 
}

//Set the click handler to the addTask Function
addButton.onclick = addTask;

//cycle over incompleteTasksHolder ul list items
for(var i = 0; i < incompleteTasksHolder.children.length; i +=1) {

  //bind events to list items's childeren (taskCompleted)
  bindTaskEvents(incompleteTasksHolder.children[i], taskCompleted);

}

//cycle over completeTasksHolder ul list items
//missing D. Typo. completeTasksHolder should be completedTasksHolder *********************
for(var i = 0; i < completedTasksHolder.children.length; i +=1) {
  //bind events to list items's childeren (taskIncomplete)
  bindTaskEvents(completedTasksHolder.children[i], taskIncomplete);
}
Anthony Lash
Anthony Lash
4,200 Points

THANK YOU, I had the same problem