IntProgLabs/front/index.js
2023-03-16 16:36:43 +04:00

46 lines
1.1 KiB
JavaScript

const intButton = document.getElementById("intButton");
const strButton = document.getElementById("strButton");
const first = document.getElementById("first");
const second = document.getElementById("second");
const operation = document.getElementById("operation");
const result = document.getElementById("result");
intButton.onclick = () => {
method("int");
};
strButton.onclick = () => {
method("str");
};
function method(parametr) {
switch (parseInt(operation.value)) {
case 1:
get("summa", parametr)
break;
case 2:
get("min", parametr)
break;
case 3:
get("multi", parametr)
break;
case 4:
get("div", parametr)
break;
};
}
function checkNum(res) {
if (res.indexOf(".") != -1)
return parseInt(res)
else
return res
}
function get(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 = res);
}