Fix NaN on result refresh

With 0 total votes, the results page would show NaN after the first
refresh. Don't divide by 0, children.
This commit is contained in:
Wolvan 2022-01-12 21:14:44 +01:00
parent cfa150cc42
commit 74a0910d11

View file

@ -60,8 +60,8 @@ function domLoaded() {
if (!el) return; if (!el) return;
el.querySelector(".poll-option-votes").innerText = value; el.querySelector(".poll-option-votes").innerText = value;
el.querySelector(".poll-bar-fill").style.width = (value / totalVotes * 100) + "%"; el.querySelector(".poll-bar-fill").style.width = totalVotes ? (value / totalVotes * 100) + "%" : "0%";
el.querySelector(".poll-bar-text").innerText = Math.round(value / totalVotes * 100); el.querySelector(".poll-bar-text").innerText = totalVotes ? Math.round(value / totalVotes * 100) : 0;
}); });
prevResult = votes; prevResult = votes;
} }