function writeDocument(variable){ document.write(variable+"<br/>"); } function countNumbers(str) { // 计数变量 var sum = 0; // 分割字符串为单字符数组 var arr = str.split(""); // 遍历数组 for(var i in arr) { // 进行类型转换 var a = Number(arr[i]); // 进行判断 if(isNaN(a)==true){ sum++; } }; console.log(arr); console.log(sum); } var str="Rome was not built in a day"; writeDocument(countNumbers(str));