Skip to main content
2 of 2
Same fields as the element of the array, not the array itself.
cbojar
  • 2.7k
  • 2
  • 15
  • 20

A small review, but your naming seems a bit repetitive.

This:

// Use _ to template the resultsTemplating details
function resultsTemplating(data, inputValue) {
    var results = data,
        resultsTemplate = _.template($("#results-template").html()),
        resultingHtml = resultsTemplate({
            results : results,
            searchVal : inputValue,
            amount: results.length
        });

    // place the generated data into the html
    $("#results-container").html(resultingHtml);
}

has results and resulting all over the place, I would go for something like this:

// Use _ to template the resultsTemplating details
function templateResults(results, searchValue) {
    var template = _.template($("#results-template").html()),
        html = resultsTemplate({
            results : results,
            searchVal : searchValue,
            amount: results.length
        });

    // place the generated data into the html
    $("#results-container").html(html);
}

I also removed the move from data to results to save a line and renamed inputValue to searchValue. I noticed that you have inputValue and searchVal, in my mind you want to be consistent and have inputValue and searchValue or inputVal and searchVal. I much prefer the fully spelled out name.

This bit is funny:

                overlayHtml = overlayTemplate({
                    name : data[i].name,
                    username : data[i].username,
                    language: data[i].language,
                    url: data[i].url,
                    description: data[i].description
                }); 

You are creating an object with the exact same properties which already exist in data[i]. Unless you have unwanted fields in data[i] that you really dont want in your template, you can simply

                overlayHtml = overlayTemplate(data[i]);

All in all, this is really great code for someone without formal training. I like the size of your functions, the level of commenting and how easy the code is to follow.

konijn
  • 34.4k
  • 5
  • 71
  • 267