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 trialroberthopman
16,502 PointsWhy does .value need to be added?
about this part:
//add a new task var addTask = function() { console.log("Add task..."); //create a new list item with the text from #new-task: var listItem = createNewTaskElement(taskInput.value);
//append listItem to incompleteTasksHolder incompleteTasksHolder.appendChild(listItem); bindTaskEvents(listItem, taskCompleted); }
--> Why not just taskInput?
2 Answers
Steven Parker
231,198 PointsThe createNewTaskElement function takes a string as its parameter.
But taskInput is an input element. The value property of an input element represents the content entered into the input as a string. So taskInput.value provides the correct type of argument to pass to createNewTaskElement.
Now it would be possible to rewrite createNewTaskElement to take an element as the parameter; but the current code requires a string.
Owa Aquino
19,277 PointsI did forgot to add ".value" in my code. And get this instead [object HTMLInputElement] for a Task value. :D
Hopes this help.
Cheres!
roberthopman
16,502 Pointsroberthopman
16,502 PointsAha, so if I rewrite the code, would it be like this: createNewTaskElement(document.getElementById("new-task").value) ?