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 trialLeah Thompson
14,997 PointsInvalid left-hand side expression in postfix operation
Me again, still trying with the project!
Following along, went to see how my code worked and I get the error "Invalid left-hand side expression in postfix operation"...
I;ve gone through it countless times, cannot see my error, so i continued... but alas I haven't altered wherever the error may be..
//User interaction does not get desired results
//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 on the page
var incompleteTasksHolder = document.getElementById("incomplete-tasks"); //incomplete-tasks
var completedTasksHolder= document.getElementById("completed-tasks"); //completed-tasks
//new task list item
var createNewTaskElement = function(taskString){
//create list item
var listItem = document.createElement("li");
//create an input check box
var checkBox = document.createElement("input");
//label
var label = document.createElement("label");
//input.edit
var editInput = document.createElement("input");
//button .edit
var editButton = document.createElement("button");
//button.delete
var deleteButton = document.createElement("button");
//each of these elements will need to be modifying
//and appended
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 new list item with the text from the #new task
var listItem = createNewTaskElement("Some New Task");
//append list item to incomplete task holder
incompleteTasksHolder.appendChild(listItem);
}
//edit existing tasks
var editTask = function(){
console.log("Edit task...");
//when the edit button is pressed
//if the class of the parent element is .editmode
//switch from .editmode
//make label text become the input's value
//else
//switch to .editmode
//input value becomes the label's text
//toggle .editmode on the parent
}
//mark tasks as complete
var taskCompleted = function(){
console.log("Task Complete...");
// when the Check box is checked
//append the task list item to the #completed-tasks
}
//delete tasks (existing)
var deleteTask = function (){
console.log("Delete task...");
//when the delete button is pressed
//remove the parent list item from the UL
}
//mark task as incomplete
var taskIncomplete = function(){
console.log("Task incomplete...");
//when the check box is unchecked
//append the list item to #incomplete-tasks
}
var bindTaskEvents = function(taskListItem, checkBoxEventHandler){
console.log("Bind list item events");
//select listitems 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 checkBoxEventHandler to the checkbox
checkBox.onchange = checkBoxEventHandler;
}
// set the click handler to the addTask function
addButton.onclick = addTask;
//cycle over incompleteTaskHolder ul li items
for(var i=0; i< incompleteTasksHolder.children.length; 1++){
bindTaskEvents (incompleteTasksHolder.children[i],taskCompleted)};
//cycle over completeTaskholder ul list items
for(var i=0; i< completedTasksHolder.children.length; 1++){
bindTaskEvents (incompleteTasksHolder.children[i],taskIncomplete)};
3 Answers
myackley35
34,574 PointsHello again, Leah!
I checked your code but I wasn't able to replicate the error you were getting. I did get Javascript errors for your "for" loops. Change out the "1++" for "i++" and you should be back on track. If you're still having the same error post a screenshot and we can figure things out from there.
Leah Thompson
14,997 PointsHi Mark, can tell what I'm up to this afternoon/evening haha
I changed the i's, still got the error, mine is highlighting that it is within the 'for' for the error, I'm using chrome, I get similar errors in safari too:
[Error] ReferenceError: Postfix ++ operator applied to value that is not a reference. global code (app.js, line 98)
I'm just unsure to what that means
Leah Thompson
14,997 PointsMark, I've done it with the help of my other half, and probably yourself.... someone (cough, me) hadn't saved before testing things.... so we commented out bits, saved and suddenly the errors went.... removed the comments, and now it works. I think your 1 to i things was probably the issue, but I never clicked save.
Long day.
Thanks again!
myackley35
34,574 PointsNot a problem!