forked from mpuchstein/VapeHP
36 lines
1.6 KiB
JavaScript
36 lines
1.6 KiB
JavaScript
const calcForm = document.getElementById('calculator') // const ist hier besser als let, da immutable
|
|
calcForm.addEventListener('submit', calculate)
|
|
|
|
function calculate(e){
|
|
let aromaamount = document.getElementById("aromaamount").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
|
|
let nicdose = document.getElementById("nicdose").value
|
|
let nicshotamount = document.getElementById("nicshotamount").value
|
|
let nicshotnicppm = document.getElementById("nicshotnicppm").value
|
|
let nicshotvg = document.getElementById("nicshotvg").value
|
|
let nicshotpg = document.getElementById("nicshotpg").value
|
|
|
|
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
|
|
}
|
|
|
|
e.preventDefault() // https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault
|
|
}
|