I tried fixing your code indentation and format but it was just unreadable for me. But anyway, I'll do it as an example you adapt it to your specific needs.
var html = "<table>";
for(var i = 0; i<someCondition; i++){
html +="<tr><td>Cell 1</td><td>Cell 2</td><tr>";
}
html += "</table>";
the error you are getting is because somewhere in your code you have something like ... + for(...)
and that doesn't work, a for loop doesn't return so it won't get anything from it.