-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
40 lines (33 loc) · 1.15 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const calcBtn = document.querySelector(".calc");
const KH = document.querySelector(".kh");
const per = document.querySelector(".per");
const amount = document.querySelector(".amount");
const mult = document.querySelector(".mult");
const output = document.querySelector(".output");
const allInputs = document.querySelectorAll("input");
const perText = document.querySelector(".per-txt");
const errMsg = "Please fill out all fields"
const lang = navigator.language || navigator.userLanguage;
//set lang if german to german
if(lang == "de"){
errMsg = "Bitte alle Felder ausfüllen";
KH.placeholder = "Kohlenhydrate";
perText.innerHTML = "pro";
per.placeholder = "Menge(z.B. 100g)";
amount.placeholder = "Menge an Essen";
mult.placeholder ="Multiplikator";
calcBtn.innerHTML = "Ausrechnen";
}
calcBtn.addEventListener("click", ()=>{
let = inputsEmpty = false;
allInputs.forEach((input) =>{
if(input.value == ""){
output.innerHTML = errMsg
inputsEmpty=true;
}
})
if(!inputsEmpty){
output.innerHTML = (((amount.value/per.value)*KH.value)/"10")*mult.value + " IU";
}
return;
})