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 Selecting Elements and Adding Events with JavaScript Perform: Event Handling

I can't get addButton recognized. I get an unexpected "(" message, but there's no error there. Pls advise.

Line 43 of the code below is flagged repeatedly. That's in the deleteTask function, but I can't find anything wrong there, either. What am I missing?

//Problem: User interaction doesn't provide any of the desired results
//Solution: Add interactivity so user can complete any & all daily tasks

//All the functions need to be triggered when an event occurs on an element
//But before we trigger the event handlers, we want to select the page elements in the DOM:
var taskInput = document.getElementById("new-task"); //new-task
var addButton = document.getElementsByTagName("button")[0]; //1st button, accessed via array notation
var incompleteTasksHolder = document.getElementById("incomplete-tasks") //incomplete-tasks
var completedTasksHolder = document.getElementById("completed-tasks"); //completed-tasks

//Add new task
var addTask = function() {
  console.log("Add task...");
//when button is pressed
  //create new list item with text from #new-task
    //input (checkbox)
    //label
    //input (text)
    //button.edit
    //button.delete
    //each element needs to be modified & appended
}

//Edit existing task
var editTask = function() {
    console.log("Edit task...");

  //When Edit button is pressed
    //if parent class is .editMode
      //switch from .editMode
      //label text becomes input's value
    //else 
      //switch to .editMode
      //input value becomes label's text

    //toggle edit mode on the parent
}

//Delete an existing task
var deleteTask = function() {
    console.log("Delete task...");
  //When Delete button is pressed
    //Remove parent list item from the ul
}

//Mark task as complete
var taskCompleted = function() {
    console.log("Complete task...");
  //when checkbox is checked
    //Append task list item to #completed-tasks
}

//Mark task as incomplete
var taskIncomplete = function() {
    console.log("Task incomplete...");
  //when checkbox is unchecked
    //Append task list item to #uncompleted-tasks
}

//Set click handler to the addTask function
addButton.onclick = addTask;
Jeff Jacobson-Swartfager
Jeff Jacobson-Swartfager
15,419 Points

Just a heads up: I've added formatting to make your code a bit more readable.

4 Answers

Jeff Jacobson-Swartfager
Jeff Jacobson-Swartfager
15,419 Points

Hi Ethan! I've just tested your code on Workspaces, but I'm not getting the error you're seeing. Everything seems to be functioning as expected.

Have you saved your code?

Yes, I have. I just deleted my history & will check it again. Thanks!

Jeff Jacobson-Swartfager
Jeff Jacobson-Swartfager
15,419 Points

The only thing I'd draw your attention to at this point is that you are missing a semicolon at the end of the incompleteTasksHolder variable declaration. But that's unlikely to be causing the error you're seeing.

Jeff: FYI--Deleting the browser cache & restarting Chrome was the solution, but your question about saving the code enabled me to shift my attention from the code itself to the environment, & thus to the solution.

Thanks again!

That seems to have done the trick. Thank you for responding!

And thanks for catching the missing semicolon!