一個JavaScript函數,它接受一個字符串參數並對其屬性進行計數。 我不知道爲什麼它不起作用我認爲console.log行存在一些問題。Javascript missing)參數列表後
function superCounter (TheWord) {
var NOWords = TheWord.split('').length;
var NOLetters = TheWord.length;
var NOSpaces = 0;
for (var i = 0; i < superCounter.length; i++)
if (TheWord[i] === " ") {
NOSpaces = +1;
}
var CTCharacters = TheWord.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g, "");
var TNCharacters = CTCharacters.length;
var AWLength = NOLetters/NOWords;
console.log("words:"
NOWords, "letters:"
NOLetters, "spaces:"
NOSpaces, "chars:"
TNCharacters, "avgLength:"
AWLength)
}
superCounter("The grintch made it happen");
調用一個函數時,每個*每個參數之間需要逗號 - 包括由換行符分隔的參數。 – adelphus