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: Traversing Elements with querySelector

Only returning 2 "Bind list item events" in console instead of 3

At the end of Andrew's video, the console shows three "Bind list item events". I'm only returning two. When I type "Bind list item events into the console, I get an error. It reads:

Uncaught syntax error: unexpected identifier

i can't find it!

Here's my code:

//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"); //incomplete-tasks
var completedTasksHolder = document.getElementById("completed-tasks"); //completed-tasks

//Add a new task
var addTask = function() {
  console.log("Add task...");
  //When the button is pressed
  //Create a new list item with the text from the #new-task:
    //input ()
    //label
    //input (text)
    //button.edit
    //button.delete
    //Each elements, needs modified and appended
}

//Edit and existing task
var editTask = function() {
  console.log("Edit task...");
  //When the edit button is pressed
    //if the class of the parent is .editMode
      //Switch from .editMode
      //label text become the input's value
    //else
      //Switch to .editMode
      //input value becomes the label's text

    //Toggle .editMode on the parent
}

//Delete and 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...");
  //When the Checkbox is checked
    //Append the task list item to the #completed-tasks
}
//Mark a task as incomplete
var taskIncomplete = function() {
  console.log("Task incomplete...");
  //When the checkbox is unchecked
    //Append the tasks 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 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 completed TasksHolder ul list items
for(var i = 0; i < completedTasksHolder.children.length; i++) {
  //bind events to list item's children (taskIncomplete)
  bindTaskEvents(completedTasksHolder.children[i], taskIncomplete);

}

Sorry - not sure why some of the code is grey and the rest is highlighted...

Ken Alger
Ken Alger
Treehouse Teacher

Edited for markup.

You had forgotten to put JavaScript after your opening backticks.

Ken

Ken Alger
Ken Alger
Treehouse Teacher

Sarah;

Usually the error message is accompanied with a line number. Was yours?

Ken

4 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Sarah;

When I use your above posted code I get all three "Bind list item events" printed in the console in both Firefox and Chrome.

What browser are you using?

Ken

Ken,

Thank you for your help.!

Huh! That's interesting. I'm using Chrome too. I tried refreshing the preview and that didn't help. It's weird because everything else is working fine.

I also checked if there was a line number with the error and I think it's 71?

Ken Alger
Ken Alger
Treehouse Teacher

Sarah;

Try moving the closing curly bracket on line 71 (it closes the bindTaskEvents = function code block) all the way to the left so that it is even with the var declaration.

Like I said, I'm not getting any errors on my system so I'm spit-balling a little here.

Ken

Ha! That totally worked! Thank you so much. I appreciate it!

I feel kind of stupid - I have to admit that I didn't think the spacing on that would matter.....

Lindsay Groves
Lindsay Groves
4,811 Points

I've been having the same problem and have gone through and double-checked everything, including the spacing of the closing curly bracket. Does anyone see something I missed? I'm getting 2 bind list item events plus an additional one on the line below in the console. Is it ok that they aren't all appearing on the same line in the console?

//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"); //incomplete-tasks
var completedTasksHolder = document.getElementById("completed-tasks"); //completed-tasks
//Add a new task
var addTask = function() {
  console.log("Add task...");
  //When the button is pressed
  //Create a new list item with the text from the #new-task:
    //input (checkbox)
    //label
    //input (text)
    //button.edit
    //button.delete
    //Each element needs to be modified and appended
}


//Edit an existing task
var editTask = function() {
  console.log("Edit task...");
  //When the Edit button is pressed
    //if the class of the parent is .editMode
       //Switch from .editMode
       //label text become the input's value
    //else
      //Switch to .editMode
      //input value becomes the label's text

    //Toggle .editMode on the parent
}


//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...");
  //When the checkbox is checked
    //Append the task list item to the #completed-tasks
}


//Mark a task as incomplete
var taskIncomplete = function() {
  console.log("Task incomplete...");
  //When the checkbox is unchecked
    //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 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++) {
    //bind events to list item's children (taskCompleted)
    bindTaskEvents(incompleteTasksHolder.children[i], taskCompleted);
}    

//Cycle over completedTasksHolder ul list items
for(var i = 0; i < completedTasksHolder.children.length; i++) {
    //bind events to list item's children (taskCompleted)
    bindTaskEvents(completedTasksHolder.children[i], taskIncomplete);
}