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