我有這個問題即時嘗試解決,但我很難得到我想要的輸出。這是我的。編寫一個函數來計算給定的字符串參數中的單個詞的數量
var stringLength = [];
function wordCount(text) {
stringLength.push(text.split(' ').join(' , '))
console.log(stringLength.length)
}
wordCount('All work and no play makes Jack a dull boy');
這應該返回'10'。任何人都可以讓我知道我要去哪裏嗎?
'這應該返回「10'' ......爲什麼?它是什麼「返回」? –
爲什麼'stringLength'是一個數組? – nnnnnn