From 856522da17348e54b0d390f10772c21b4029e9bd Mon Sep 17 00:00:00 2001 From: ilyayudovin Date: Mon, 29 Jun 2020 17:31:51 +0300 Subject: fix: make code redably clear --- src/components/PollCard/PollCard.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/components/PollCard') diff --git a/src/components/PollCard/PollCard.tsx b/src/components/PollCard/PollCard.tsx index f222a63..f82ea44 100644 --- a/src/components/PollCard/PollCard.tsx +++ b/src/components/PollCard/PollCard.tsx @@ -72,10 +72,13 @@ const PollCard: React.FC = ({ initialPoll, navigate }) => { const handleLeft = () => vote('left'); const handleRight = () => vote('right'); - let leftPercentage = Math.round(100 * (left.votes / (left.votes + right.votes))); - let rightPercentage = 100 - leftPercentage; + let leftPercentage; + let rightPercentage; - if(Number.isNaN(leftPercentage) && Number.isNaN(rightPercentage)){ + if (left.votes || right.votes) { + leftPercentage = Math.round(100 * (left.votes / (left.votes + right.votes))); + rightPercentage = 100 - leftPercentage; + } else { leftPercentage = 0; rightPercentage = 0; } -- cgit v1.2.3