workshopper / learnyounode

Learn You The Node.js For Much Win! An intro to Node.js via a set of self-guided workshops.
Other
7.24k stars 1.84k forks source link

Exercise: 9, what does the extra function do? #659

Closed PRANAY100 closed 4 years ago

PRANAY100 commented 5 years ago

can anyone tell why my solution doesn't work? while its some what similar to official solution .. var http = require('http'); var bl = require('bl'); let count = 0; const results = [];

for (let i = 0; i < 3; i++) { // what makes the difference by adding a function here, instead of for loop? http.get(process.argv[i + 2], function (res) { res.setEncoding('utf8'); res.pipe(bl(function (err, data) { if (err){ return console.error(err); } results[i] = data.toString(); count ++; if (count == 3) { printResults() } })); });

}

function printResults() { for (let i = 0; i < 3; i++) { console.log(results[i]); } }

Originally posted by @PRANAY100 in https://github.com/workshopper/learnyounode/issues/625#issuecomment-468150927

AnshulMalik commented 4 years ago

Hi @PRANAY100 This solution should work imo, is count++ same as count ++?

PRANAY100 commented 4 years ago

yeah you are right @AnshulMalik that was a silly mistake