<div id="demo"></div>
function findSolution(target) {
  function find(start, history) {
    if (start === target) {
      document.getElementById("demo").innerHTML = history;
      return history;
    } else if (start > target) {
      return null;
    }
    
    var found = find(start + 5, "(" + history + " + 5)");
    if (!found) found = find(start * 3, "(" + history + " * 3)");
    return found;
  }
  return find(1, "1");
}

findSolution(13);

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.