Your function must be returning a string rather than the div node. And appendChild can only append a node.
e.g., if you try to appendChild to the string:
var z = '<p>test satu dua tiga</p>'; // is a string document.body.appendChild(z);
The above code will give error.
Following code will work:
var z = document.createElement('p'); // is a node z.innerHTML = 'test satu dua tiga'; document.body.appendChild(z);