const calculateButton = document.getElementById("calculate"); const calculateStrButton = document.getElementById("calculateStr"); const first = document.getElementById("first"); const second = document.getElementById("second"); const select = document.getElementById("operation"); const result = document.getElementById("result"); calculateButton.onclick = function() { calculate("num"); }; calculateStrButton.onclick = function() { calculate("str"); }; function calculate(parametr) { switch (parseInt(select.value)) { case 1: doSmth("plus", parametr) break; case 2: doSmth("minus", parametr) break; case 3: doSmth("mult", parametr) break; case 4: doSmth("div", parametr) break; }; } function checkNum(res) { if (res.indexOf(".") != -1) return parseInt(res) else return res } function doSmth(address, type) { console.log("Тип " + type) fetch(`http://localhost:8080/${address}?first=${first.value}&second=${second.value}&type=${type}`) .then(response => response.text()) .then(res => result.innerHTML = checkNum(res)); }