From 74a0910d1176da975611882be6709bf314f64e08 Mon Sep 17 00:00:00 2001 From: Wolvan Date: Wed, 12 Jan 2022 21:14:44 +0100 Subject: [PATCH] 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. --- frontend/static/js/result.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/static/js/result.js b/frontend/static/js/result.js index e62af22..6fb9684 100644 --- a/frontend/static/js/result.js +++ b/frontend/static/js/result.js @@ -60,8 +60,8 @@ function domLoaded() { if (!el) return; el.querySelector(".poll-option-votes").innerText = value; - el.querySelector(".poll-bar-fill").style.width = (value / totalVotes * 100) + "%"; - el.querySelector(".poll-bar-text").innerText = Math.round(value / totalVotes * 100); + el.querySelector(".poll-bar-fill").style.width = totalVotes ? (value / totalVotes * 100) + "%" : "0%"; + el.querySelector(".poll-bar-text").innerText = totalVotes ? Math.round(value / totalVotes * 100) : 0; }); prevResult = votes; }