const operateButton = document.getElementById("operate"); const val1 = document.getElementById("val1"); const val2 = document.getElementById("val2"); const select = document.getElementById("operation"); const finish = document.getElementById("finish"); operateButton.onclick=function(){ operate(); }; function operate(){ switch(parseInt(select.value)){ case 1: doOperation("calc1") break; case 2: doOperation("calc2") break; case 3: doOperation("calc3") break; case 4: doOperation("calc4") break; }; } function checkNumber(res){ if(res.indexOf(".") != -1){ return parseInt(res); } else{ return res; } } async function doOperation(address) { const response = await fetch(`http://localhost:8080/${address}?val1=${val1.value}&val2=${val2.value}`) let res = await response.text() finish.innerHTML = checkNumber(res); }