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 Traversing and Manipulating the DOM with JavaScript Perform: Modifying Elements

Why 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
Steven Parker
231,275 Points

:point_right: The 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.

Aha, so if I rewrite the code, would it be like this: createNewTaskElement(document.getElementById("new-task").value) ?

Owa Aquino
Owa Aquino
19,277 Points

I did forgot to add ".value" in my code. And get this instead [object HTMLInputElement] for a Task value. :D

Hopes this help.

Cheres!