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

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,254 Points

Console Quirks

Not so much something I'm stuck with more a matter of curiosity.

When I was advancing in the Interactive Javascript Web Pages course.

Following the course I made the following code.

//PLANNING: 

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...");

    //#new-task
//when button is pressed    //create a task  
  //(createe a new list item with the text from #new-task.
    //input checkbox 
    //label
    //input[text]
    //button .edit
    //button .delete
    //Each elent will need to be modified and appended.         
}

//Edit an exisiting 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
      //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 (li)  
    //
}

var taskCompleted = function() {

console.log("Completed Task...");
//Mark a task as complete.
  //when the checkbox is checked
     //append the task list item to the #completed-tasks
}

var taskIncomplete = function() {

console.log("Incompleted Tasks. Task...");
//Mark a task as incomplete.
   //when the checkbox is unchecked 
     //append the task to incomplete tasks. 
}


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

var bindTaskEvents = function(taskListItem, checkBoxEventHandler) {

 console.log("bind list items...");
 //select list items 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 the deleteTask to the delete button
    deleteButton.onclick = deleteTask;
    // bind the taskCompleted to the checkbox
    checkbox.onchange = checkBoxEventHandler;
/**/


}

//Cycle over the incompletesTaskHolder ul list items

for (var i=0; i < incompleteTasksHolder.children.length; i++) {

     //bind events to list items children(taskCompleted)
     bindTaskEvents(incompleteTasksHolder.children[i], taskCompleted);
    }
//Cycle over the completeTasksHolder ul list items
  //for each li 
for (var i=0; i < completedTasksHolder.children.length; i++) {
    // bind events to list items children (taskIncomplete)
    bindTaskEvents(completedTasksHolder.children[i], taskIncomplete);
   }

But the interesting thing is the way the console reacts.

Outside workspaces this is the output you get:

(2)bind list items... app.js:69
bind list items... app.js:69

In workspaces you get.

(3) bind list items... app.js:69

Is there a JS expert knows why this is? :-)

Jim Hoskins
Jim Hoskins
Treehouse Guest Teacher

While I'm not sure exactly why there is a difference, it's not a big deal. They're both equivalent to

bind list items... app.js:69
bind list items... app.js:69
bind list items... app.js:69

The console groups identical logs into a single line when they appear consecutively, as a convenience. This is so if you get a log call in a loop, you don't see thousands of lines.

In this case, it looks like for whatever reason, in one case it grouped 2, and showed the third, and another time it got all 3 grouped. It's really up to how chrome implements its grouping behavior.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,254 Points

Thanks Jim yes I take it to be just a difference in one console window to the other. I wondered if it might be something to do with the workspaces as the different locations were one of my workspaces and a location on my hard drive.

Either way I'm confident it's just a simple thing and not a bug to worry about. :-)

1 Answer

I'm getting am error for this exact exercise. I think it's part of the same problem.

Maybe you can help me?

https://teamtreehouse.com/forum/todo-app-undefined-error