// Code goes here

var tree = {
  text : "Parent",
  url: '/decendants/Child1',
  children: [{
    text : "Child1",
    url: '/decendants/Child1',
    children: []
    },{
    text: "Child2",
    url: '/decendants/Child2',
    children: [{
      text : "Grandchild1",
      url: '/decendants/Grandchild1',
      children: []
      },{
      text : "Grandchild2",
      url: '/decendants/Grandchild2',
      children: []
      },{
      text : "Grandchild3",
      url: '/decendants/Grandchild3',
      children: []
    }]
    },{
    text: "Child3",
    url: '/decendants/Child3',
    children: [{
      text : "Grandchild4",
      url: '/decendants/Grandchild4',
      children: []
      },{
      text : "Grandchild5",
      url: '/decendants/Grandchild5',
      children: []
      },{
      text : "Grandchild6",
      url: '/decendants/Grandchild6',
      children: []
    }]
  }]
};
    
var rawData = [];
    
$(document).ready(function(){
  var output = markUpBuilder(tree, '<li><a href="url">text</a></li>');
  
  $('.content').html(output);
});

function markUpBuilder(menuData, template, isRecurse){
  var result = [];
  var mergedTemplate = template;
  var displayTopLevelNode = hasTopLevelNode(isRecurse, menuData.text);
  var displayMenuItem = hasValidMenuText(menuData.text);
  var displayChildren = hasChildren(menuData);
  
  if(displayTopLevelNode) {
    result.push('<ul>');
  }  
  
  for (var propertyName in menuData) {
    if (menuData.hasOwnProperty(propertyName)) {
      
      if (propertyName !== 'children') {
        mergedTemplate = mergedTemplate.replace(propertyName, menuData[propertyName]);
      }
      
      else {
        
        if (displayMenuItem) {
          result.push(mergedTemplate.replace('</li>',''));
        }
        
        if (displayChildren) {
          result.push('<ul>');
        
          for (var children in menuData[propertyName]) {
            var subMenu = markUpBuilder(menuData[propertyName][children], template, true);
            result.push(subMenu);
          }
        
          result.push('</ul>');
        }
        
        if (displayMenuItem) {
          result.push('</li>');
        }
        
      }
      
    }
  }
  
  if(displayTopLevelNode) {
    result.push('</ul>');
  }  
    
  return result.join('\n');
}

function hasTopLevelNode(isRecurse, parentMenuText) {
  isRecurse = isRecurse || false;
  
  return !isRecurse && parentMenuText;
}

function hasValidMenuText(menuText) {
  var result = false;
  
  if (typeof menuText !== undefined && menuText.trim() !== '') {
    result = true;
  }
  
  return result;
}

function hasChildren(menuData){
  var result = false;
  
  if (menuData.children.length > 0) {
    result = true;
  }
  
  return result;
}

@@ -1,1059 +1,4 @@
-// Code goes here%0A%0Avar tree = %7B%0A  text : %22Parent%22,%0A  url: '/decendants/Child1',%0A  children: %5B%7B%0A    text : %22Child1%22,%0A    url: '/decendants/Child1',%0A    children: %5B%5D%0A    %7D,%7B%0A    text: %22Child2%22,%0A    url: '/decendants/Child2',%0A    children: %5B%7B%0A      text : %22Grandchild1%22,%0A      url: '/decendants/Grandchild1',%0A      children: %5B%5D%0A      %7D,%7B%0A      text : %22Grandchild2%22,%0A      url: '/decendants/Grandchild2',%0A      children: %5B%5D%0A      %7D,%7B%0A      text : %22Grandchild3%22,%0A      url: '/decendants/Grandchild3',%0A      children: %5B%5D%0A    %7D%5D%0A    %7D,%7B%0A    text: %22Child3%22,%0A    url: '/decendants/Child3',%0A    children: %5B%7B%0A      text : %22Grandchild4%22,%0A      url: '/decendants/Grandchild4',%0A      children: %5B%5D%0A      %7D,%7B%0A      text : %22Grandchild5%22,%0A      url: '/decendants/Grandchild5',%0A      children: %5B%5D%0A      %7D,%7B%0A      text : %22Grandchild6%22,%0A      url: '/decendants/Grandchild6',%0A      children: %5B%5D%0A    %7D%5D%0A  %7D%5D%0A%7D;%0A    %0Avar rawData = %5B%5D;%0A    %0A$(document).ready(function()%7B%0A  var output = markUpBuilder(tree, '%3Cli%3E%3Ca href=%22url%22%3Etext%3C/a%3E%3C/li%3E');%0A  %0A  $('.content').html(output);%0A%7D);%0A%0A
 func

Update markupBuilder.js