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 trialcassac
9,628 PointsWhat's the point of the "else" clause in the "editTask" function?
If I remove the "else" clause it seems the apps functions with no problems. Why is it included?
var editTask = function() {
console.log("Edit task...");
var listItem = this.parentNode;
var editInput = listItem.querySelector("input[type=text]");
var label = listItem.querySelector("label");
var containsClass = listItem.classList.contains("editMode");
//if the class of the parent is .editMode
if (containsClass) {
//Switch from .editMode
//label text become the input's value
label.innerText = editInput.value;
} else {
//Switch to .editMode
//input value becomes the label's text
editInput.value = label.innerText;
}
//Toggle .editMode on the listItem
listItem.classList.toggle("editMode");
}
2 Answers
cassac
9,628 PointsI was having a hard time seeing how these things correlate with each other.
I replaced
editInput.value = label.innerText;
with
editInput.value = "What's the point of this?";
And can see the correlation. Thanks for the input!
Devin Scheu
66,191 PointsThe else clause does what it says, if the if statement is not true then the code in the else clause will execute, sometimes its need and sometimes its just there in case there is an error. This is checking if whatever the parent element is, is in edit mode.