learnyounode icon indicating copy to clipboard operation
learnyounode copied to clipboard

MAKE IT MODULAR another verify error

Open locdoan12121997 opened this issue 7 years ago • 4 comments

I'm getting an error when verifying the "Make It Modular" exercise.

Here's my make-it-modular.js:

var fs = require('fs');
var path = require('path');

module.exports = function (dir, ext,callback){
  fs.readdir(dir,function(err,list){
    if (err)
      return callback(err);
    for (var i = 0; i< list.length; i++){
      if (path.extname(list[i]) === ('.'+ext))
        callback(list[i]);
    }
  })
}

My module named filtered-ls1.js:

var mymodule = require('./make-it-modular.js');
mymodule(process.argv[2], process.argv[3],console.log);

And here's the output when I run learnyounode verify make_it_modular.js:

Your submission results compared to the expected:

                 ACTUAL                                 EXPECTED
────────────────────────────────────────────────────────────────────────────────

   "CHANGELOG.md"                      ==    "CHANGELOG.md"
   "LICENCE.md"                        ==    "LICENCE.md"
   "README.md"                         ==    "README.md"
   ""                                  ==    ""

────────────────────────────────────────────────────────────────────────────────

 ✓

 Submission results match expected

 ✓

 Additional module file exports a single function

 ✓

 Additional module file exports a function that takes 3 arguments

 ✓

 Additional module file handles errors properly

 ✓

 Additional module file handles callback argument

C:\Users\win\AppData\Roaming\npm\node_modules\learnyounode\node_modules\workshopper-exercise\exercise.js:188
    processors[i].call(self, mode, function (err, pass) {
                 ^

TypeError: Cannot read property 'call' of undefined
    at next (C:\Users\win\AppData\Roaming\npm\node_modules\learnyounode\node_modules\workshopper-exercise\exercise.js:188:18)
    at C:\Users\win\AppData\Roaming\npm\node_modules\learnyounode\node_modules\workshopper-exercise\exercise.js:195:7
    at callback (C:\Users\win\AppData\Roaming\npm\node_modules\learnyounode\exercises\make_it_modular\verify.js:26:15)
    at modFileError (C:\Users\win\AppData\Roaming\npm\node_modules\learnyounode\exercises\make_it_modular\verify.js:31:5)
    at C:\Users\win\AppData\Roaming\npm\node_modules\learnyounode\exercises\make_it_modular\verify.js:119:18
    at C:\Users\win\Desktop\Node js\Nodeschool\learnyounode\make-it-modular.js:9:9
    at FSReqWrap.oncomplete (fs.js:123:15)

locdoan12121997 avatar May 26 '17 04:05 locdoan12121997

Hey, which node version are you using ? @locdoan12121997

AnshulMalik avatar Jun 02 '17 03:06 AnshulMalik

please take a look at https://github.com/workshopper/learnyounode/issues/500 the main issue for that step is callback execution inside loop. Please take callback out from loop and task will be done

UjinKosy avatar Jun 05 '17 14:06 UjinKosy

@locdoan12121997 your module is defined as

module.exports = function (dir, ext, callback){/*code here*/}

so function() expects three input parameters, dir = directory to parse, ext= file extension to filter and callback.

callback must be a function that prints out error or result list.

Intead of printing out the file name inside module you must print this info in your callback function, defined as parameter or somewhere else in caller.

var foo = function(parm1,param2,pram3...){/*code here*/}

moduleFunction (dir, ext,foo){/*code here*/}

or 

moduleFunction(dir, ext,function(parm1,param2,pram3...){/*code here*/});

vveliu avatar Jun 22 '17 15:06 vveliu

@locdoan12121997 Still stuck?

AnshulMalik avatar Aug 29 '17 06:08 AnshulMalik