My return variable keeps coming back undefined. Can someone please explain why? as far as I can tell it should be in scope.
var countBs = function(word) {
var count = 0;
for (var i = 0; i < word.length; i++){
if (word.charAt[i] == 'B'){
count += 1;
return count;
};
};
};
console.log(countBs('BBABBAB'))
word.charAtis a function. When you develop - ensure you understand every expression in your code and that you have checked that every expression returns exactly what you expect - using a debugger or at least aconsole.logword.charAt(i)