IP_Aleikin_PIbd-22/frontend/js/script.js

59 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-03-06 15:00:42 +04:00
let form = document.getElementById("form");
let info = document.getElementById("res");
form.onsubmit = async (e) => {
e.preventDefault();
if(form.num1.value === "") return;
if(form.num2.value === "") return;
let index = form.selected.selectedIndex;
2023-04-02 21:28:45 +04:00
let indexType = form.type.selectedIndex;
2023-03-06 15:00:42 +04:00
let op = form.selected.options[index].textContent;
2023-04-02 21:28:45 +04:00
let type = form.type.options[indexType].textContent;
2023-03-06 15:00:42 +04:00
let res = "";
2023-04-02 21:28:45 +04:00
function calc() {
switch(op) {
case "+":
return "sum";
break;
case "-":
return "diff";
break;
case "*":
return "mul";
break;
case "/":
return "div";
break;
}
}
function typeOfCalc() {
switch(type) {
case "Int":
return "int";
break;
case "String":
return "string";
2023-03-06 15:00:42 +04:00
break;
2023-04-02 21:28:45 +04:00
case "FloatArray":
return "floatArray";
2023-03-06 15:00:42 +04:00
break;
2023-04-02 21:28:45 +04:00
}
2023-03-06 15:00:42 +04:00
}
2023-04-02 21:28:45 +04:00
if (form.num2.value == 0 && calc(op) == "divide") return;
res = await fetch(`http://localhost:8080/${calc()}?num1=${form.num1.value}&num2=${form.num2.value}&operationType=${typeOfCalc()}`)
res = await res.text();
2023-03-06 15:00:42 +04:00
info.textContent = res;
}