Could someone explain why is this not allowed in functions? shouldnt it return a “node” when u return a value from a functions. I tried to refrector code for better cohesion , in strongly typed languges the logic should work if functions are returning the value =/. Am i missing something here ? appreciate any help
//failed
function addToTargetList()
{
targetList.appendChild(addItemsToList);//error
text.value ="";
}
function addItemsToList(){
var list = document.createElement("li");
list.classList.add("items");
list.textContent = text.value;
return list;
}
//will work but bad cohesion
function addToTargetList()
{
var list = document.createElement("li");
list.classList.add("items");
list.textContent = text.value;
targetList.appendChild(addItemsToList);
text.value ="";
}