Thursday, 1 June 2017

Cannot read property 'toLowerCase' of undefined javascript

function isIsogram(word) {

var entered = word; if (typeof (entered) === undefined) { return false }

var passed = true;

wordest = entered.toLowerCase();

var counts = {};

for (var i = 0; i <= wordest.length; i++) { var letter = wordest.toString().charAt(i)

if (counts[letter]) {
  counts[letter] += 1
}
else {
  counts[letter] = 1
}

if (counts[letter] > 1) {
  return passed = false
}

}

return passed };

isIsogram("Altruistic");

the code above works fine when i try to run it in the browser javascript console, but it return the error below each time i try running it on qualified.io it uses Node v6.6.0.

/home/codewarrior/mocha:16 for (i = 0; i <= wordest.length; i++) { ^

TypeError: Cannot read property 'length' of undefined at isIsogram (/home/codewarrior/mocha:16:27) at Suite.describe (/home/codewarrior/mocha:42:23) at Object.create (/.npm-global/lib/node_modules/mocha/lib/interfaces/common.js:114:19) at context.describe.context.context (/.npm-global/lib/node_modules/mocha/lib/interfaces/bdd.js:44:27) at Suite.describe (/home/codewarrior/mocha:41:5) at Object.create (/.npm-global/lib/node_modules/mocha/lib/interfaces/common.js:114:19) at context.describe.context.context (/.npm-global/lib/node_modules/mocha/lib/interfaces/bdd.js:44:27) at /home/codewarrior/mocha:40:1 at Object. (/home/codewarrior/mocha:64:11) at at Object.Module._extensions..js (module.js:565:10) at Module.load (module.js:473:32) at tryModuleLoad (module.js:432:12) at Function.Module._load (module.js:424:3) at Module.require (module.js:483:17) at require (internal/module.js:20:19) at /.npm-global/lib/node_modules/mocha/lib/mocha.js:222:27 at Array.forEach (native) at Mocha.loadFiles (/.npm-global/lib/node_modules/mocha/lib/mocha.js:219:14) at Mocha.run (/.npm-global/lib/node_modules/mocha/lib/mocha.js:487:10) at Object. (/.npm-global/lib/node_modules/mocha/bin/_mocha:459:18) at at Object.Module._extensions..js (module.js:565:10) at Module.load (module.js:473:32) at tryModuleLoad (module.js:432:12) at Function.Module._load (module.js:424:3) at Module.runMain (module.js:590:10) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:509:3



via D-Beloved

No comments:

Post a Comment