function countWords(str) {
let counts = {};
let words = str.split(' ');
for (let word of words) {
if (word.length > 0) {
if (!(word in counts)) {
counts[word] = 0;
}
counts[word] += 1;
}
}
return counts;
}
wordsCounter.innerText = text.replace(/s+/g, " ").split(" ").length