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
Doug Hawkinson
Full Stack JavaScript Techdegree Student 25,073 PointsInteractive Web Pages with JavaScript - What is an object/
I think I missed something key in this module. Here are the error messages I am dealing with:
Uncaught TypeError: Cannot read property 'length' of undefined app.js:134
Uncaught TypeError: incompleteTasksHolder.appendChild is not a function app.js:54
the variable in question is "incompleteTasksHolder" but the same could be said for "completedTasksHolder" at line 139, if I comment out 134 to 137.
"incompleteTasksHolder" gets initialized as document.getElementById("incomplete-tasks"); at line 6
"completedTasksHolder" gets initialized as document.getElementById("completed-tasks"); at line 7
I set two variables at lines 8 and 9 ($incomplete and $complete) so that I could retain the initial values of "incompleteTasksHolder" & "completedTasksHolders"
they look like this:
<!-- $incomplete -->
<ul id="incomplete-tasks">
<li>
<input type="checkbox">
<label>Pay Bills</label>
<input type="text">
<button class="edit">Edit</button>
<button class="delete">Delete</button>
</li>
<li class="editMode">
<input type="checkbox">
<label>Go Shopping</label>
<input type="text" value="Go Shopping">
<button class="edit">Edit</button>
<button class="delete">Delete</button></li></ul>
<!-- $complete -->
<li>
<input type="checkbox" checked="">
<label>See the Doctor</label>
<input type="text">
<button class="edit">Edit</button>
<button class="delete">Delete</button>
</li>
However when we get to line 134 "incompleteTasksHolder looks like this :
// incompleteTasksHolder
function () {
console.log("Task Incomplete...");
// when the checkbox is unchecked
// append the task to the #incompleted-tasks
}
and completedTasksHolder looks like this at line 139:
// completedTasksHolder
function () {
console.log("Task Complete...");
// When the check box is pressed
// append the task to the #completed-tasks
}
Quite clearly I have missed something because it makes perfect sense that each of the variables in question will have an undefined .children element by the time lines 134 and 139 are processed since they have been reinitialized as anonymous functions() at lines 94 and 101 respectively.
/* 94 */ var completedTasksHolder = function() {
/* 101 */ var completedTasksHolder = function() {
/* 134 */ for(var i = 0; i < incompleteTasksHolder.children.length; i+=1) {
/* 139 */ for(var i = 0; i < completedTasksHolder.children.length; i+=1) {
This is probably way too confusing to deal with so I will shut up and give you the codepen lin
3 Answers
Jeff Jacobson-Swartfager
15,419 PointsSkimming through your code, it doesn't look like you ever actually defined taskCompleted. If you define that, you'll be able to make some more progress.
Doug Hawkinson
Full Stack JavaScript Techdegree Student 25,073 PointsJeff I appreciate that. Now, how did you do it? I'm sure this won't be my last question.
Jeff Jacobson-Swartfager
15,419 PointsI formatted your question with markdown (take a look at the Markdown Cheatsheet link right below the text entry field for the posts).
Bobby Verlaan
29,837 PointsAs Jeff said. taskCompleted wasn't defined before.
Take in the code below
for (var i = 0; i < incompleteTasksHolder.children.length; i += 1) {
if (window.CP.shouldStopExecution(1)) {
break;
}
bindTaskEvents(incompleteTasksHolder.children[i], taskCompleted);
}
Looking at the for-loop. Are you trying to loop through the items in the incompleteTasksHolder array? Or are you trying to loop through the items of a child of one of the items in the incompleteTasksHolder array?
Jeff Jacobson-Swartfager
15,419 PointsJeff Jacobson-Swartfager
15,419 PointsHi Doug,
I formatted your question to make it a bit more readable.