simple underscore.js projects, walk through, & tutorial
I won't be typing much in these. Rather, I intend to let the code speak for itself.
_.range examples
var outputTextOne = _.map(_.range(0, 101, 1), function(n){return ' ' + n;});
_.range feeds values from 0 to 100 at a step of 1
_.map with the return ' ' + n, returns the range with an empty space
before it in a string format. Sole purpose of this is so the
string will wrap in the HTML.
Output below:
Nada Yet
var outputTextTwo = _.map(_.range(0, 101, 1), function(n){return ' ' + n*n;});
Outputs below. n*n is the only difference
Nada Yet
var outputTextThree = _.map(_.range(0, 101, 1), function(n){return ' ' + n*n*n;});
Once again, outputs below. But this time, it's cubed (n^3).
Nada Yet
Preparing the HTML
<body onload="onLoadFunction();">
Insures the JavaScript doesn't run until the page is loaded (and so the output has somewhere to go).
<div id="outputOne">
Nada Yet
</div>
Three of these give the output a div tag to go into.
function onLoadFunction(){
document.getElementById('outputOne').innerHTML = outputTextOne;
document.getElementById('outputTwo').innerHTML = outputTextTwo;
document.getElementById('outputThree').innerHTML = outputTextThree;
}
And this pushes the JavaScript string variable into the div tag.