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

Nick Tolbert
Nick Tolbert
12,003 Points

[RESOLVED]the addTask function is not running the console.log when addButton is click

am using google chrome and I am not getting any console errors, but I have no clue if the button works .

treehouse snapshot

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


var taskInput = document.getElementById("new-task"); //#new-task
var addButton =document.getElementsByTagName("button")[0] ; //first button on pg
var incompleteTasksHolder = document.getElementById("incomplete-tasks"); //ul #incomplete-tasks
var completeTasksHolder = document.getElementById("completed-tasks");//complete-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 #new-task:
  //input (checkbox)
    //label
    //input (text)
    //button.edit
    //button.delete
    //Each elements, needs modified and appended
}

//Edit an existing task
var editTask = function(){
    console.log=("editTask...");
  //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 =("deleteTask...");
  //When the Delete button is pressed
    //Remove the parent list item from the ul
}


//Mark a task as complete
var completeTask = 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 incompleteTask = function(){
    console.log=("Task incomplete...");

  //When the checkbox is unchecked
    //Append the task list item to the #incomplete-tasks
}



//set the click handler to the addTask to function
addButton.onclick = addTask;

2 Answers

Hi Nick, You don't need the = after console.log.

//Should be
var addTask = function (){
    console.log("add task...");
}

//not
var addTask = function(){
    console.log =("add Task...");
}
Daniel Botta
Daniel Botta
17,956 Points

I found the problem:

//set the click handler to the addTask to function
addButton.onclick = addTask;

onclick is a method/function. So you need to call it like so:

addButton.onclick(function() {
     addTask();
});

or you could also do the following for a simplified version:

addButton.onclick(addTask);
Nick Tolbert
Nick Tolbert
12,003 Points

I have tried all of these and none of them work. all of my function have a null value but I don't know why or if this is part of the problem p.s. Thanks anyways