Counting upper and lower case characters in a string

You can use match() and regular expressions.

var str = "aBcD"; 
var numUpper = (str.match(/[A-Z]/g) || []).length;    // 2

Use regular expressions.

Example

var s = "thisIsAstring";
var numUpper = s.length - s.replace(/[A-Z]/g, '').length;  

// numUpper = 2

Se more at JavaScript replace/regex


Not sure if whole problem, but bad paren on this one

if(text.charAt(letters)) == " " && text(letters) < text.length)
                       ^

Should be

if(text.charAt(letters) == " ") && text(letters) < text.length)
                              ^

And actually I'd make it

if((text.charAt(letters) == " ") && (text(letters) < text.length))