diff --git a/src/js/displayToggles.js b/src/js/displayToggles.js index 4e1f82d..782a5f0 100644 --- a/src/js/displayToggles.js +++ b/src/js/displayToggles.js @@ -36,8 +36,13 @@ function showStats() { detailsPanel.style.display = 'block'; const wordStats = getWordsStats(); const numberOfWordsHTML = `
Number of Words
${wordStats.numberOfWords.map(stat => `${stat.name}${stat.value}`).join(' ')}
Word Length
Shortest${wordStats.wordLength.shortest}
+ Longest${wordStats.wordLength.longest}
+ Average${wordStats.wordLength.average}
Letter Distribution
${wordStats.letterDistribution.map(stat => `${stat.letter}${stat.percentage.toFixed(2)}`).join(' ')}
${wordStats.totalLetters} Total Letters
`; + + detailsPanel.innerHTML = numberOfWordsHTML + wordLengthHTML + letterDistributionHTML + totalLettersHTML; } function getWordsStats() { @@ -109,7 +114,7 @@ function getWordsStats() { }); wordStats.totalLetters = totalLetters; - wordStats.wordLength.average = totalLetters / words.length; + wordStats.wordLength.average = words.length > 0 ? totalLetters / words.length : 0; for (const letter in numberOfLetters) { if (numberOfLetters.hasOwnProperty(letter)) {