javascript - Program keeps returning cannot read property toLowerCase of Undefined -


function isisogram(str) {      if (typeof str === undefined) {         return true     }      var passing = true;     var strn = str.tolowercase()     var counts = {}      (i = 0; <= strn.length; i++) {         var letter = strn.charat(i)          if (counts[letter]) {             counts[letter] = 1 + counts[letter]         } else {             counts[letter] = 1         }          if(counts[letter] > 1) {             return passing = false         }     }     return passing } 

after running code against tests keep getting; typeerror: cannot read property 'tolowercase' of undefined. please how resolve , getting wrong?

it should "undefined".

e.g.

if (typeof str === "undefined") 

but replace line check null parameters.

if (!str) {   return true; } 

e.g.

function isisogram(str) {      if (!str) {      return true;    }      var passing = true;      var strn = str.tolowercase();      var counts = {};      (i = 0; <= strn.length; i++) {        var letter = strn.charat(i);        if (counts[letter]) {        counts[letter] = 1 + counts[letter];      } else {        counts[letter] = 1;      }        if (counts[letter] > 1) {        return passing = false;      }      }      return passing;  }    console.log(isisogram());  console.log(isisogram(null));  console.log(isisogram("asdf"));


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -