From 1f881cb77122826912e210f5b1866f586cd15735 Mon Sep 17 00:00:00 2001 From: Matthias Puchstein Date: Sat, 27 Nov 2021 14:12:20 +0100 Subject: [PATCH] added some error handling --- aromacalc.js | 32 ++++++++++++++++++-------------- index.html | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/aromacalc.js b/aromacalc.js index 6751894..3c95ef4 100644 --- a/aromacalc.js +++ b/aromacalc.js @@ -3,7 +3,7 @@ buttoncalc.addEventListener("click", calculate) function calculate(){ let aromaamount = document.getElementById("aromaamount").value - let aromaconc = document.getElementById("aromaconc").value + let aromaconc = document.getElementById("aromaconc").value / 100 let vg = document.getElementById("vg").value let pg = document.getElementById("pg").value let other = document.getElementById("other").value @@ -13,17 +13,21 @@ function calculate(){ let nicshotvg = document.getElementById("nicshotvg").value let nicshotpg = document.getElementById("nicshotpg").value - document.getElementById("results").style.display="block" - let volume = aromaamount / aromaconc - let countnicshot = (volume * nicdose) / (nicshotamount * nicshotnicppm) - let amountothers = volume / 100 * other - let amountvg = volume / 100 * vg - countnicshot * nicshotamount * nicshotvg / 100 - let amountpg = volume / 100 * pg - countnicshot * nicshotamount * nicshotpg / 100 - aromaamount - - document.getElementById("volume").value = volume - document.getElementById("countnicshot").value = countnicshot - document.getElementById("amountothers").value = amountothers - document.getElementById("amountvg").value = amountvg - document.getElementById("amountpg").value = amountpg -} + if(vg * 1 + pg * 1 + other * 1 != 100){ + } else if(nicshotvg * 1 + nicshotpg * 1 != 100){ + } else { + document.getElementById("results").style.display="block" + let volume = aromaamount / aromaconc + let countnicshot = (volume * nicdose) / (nicshotamount * nicshotnicppm) + let amountothers = volume / 100 * other + let amountvg = volume / 100 * vg - countnicshot * nicshotamount * nicshotvg / 100 + let amountpg = volume / 100 * pg - countnicshot * nicshotamount * nicshotpg / 100 - aromaamount + + document.getElementById("volume").value = volume + document.getElementById("countnicshot").value = countnicshot + document.getElementById("amountothers").value = amountothers + document.getElementById("amountvg").value = amountvg + document.getElementById("amountpg").value = amountpg + } +} diff --git a/index.html b/index.html index 883ec27..9800665 100644 --- a/index.html +++ b/index.html @@ -12,7 +12,7 @@ - +