diff --git a/main.ts b/main.ts index 530291a..b682488 100644 --- a/main.ts +++ b/main.ts @@ -127,8 +127,8 @@ function renderPokemonIndex(pokemons: Array): string { .join('\n'); const getStatBar = (value: number, maxValue: number) => { const percentage = Math.round((value / maxValue) * 100); - const greenThreshold = 35; - const yellowThreshold = 20; + const greenThreshold = 100 / (6 - 1); // 6: because there are 6 stats + const yellowThreshold = 100 / (6 + 1); // +-1: to move a bit more/less from 6 let backgroundColor; if (percentage >= greenThreshold) { @@ -147,13 +147,13 @@ function renderPokemonIndex(pokemons: Array): string { `; }; - + const total_stats = pokemon.stats.reduce((a, b) => a + b) const statsTableRows = pokemon.stats .map(stat => ` ${(stat.name === 'hp') ? 'HP': stat.name.charAt(0).toUpperCase() + stat.name.slice(1)}: ${stat.value} - ${getStatBar(stat.value, 255)} + ${getStatBar(stat.value, total_stats)} `) .join('\n');