70 lines
2.1 KiB
JavaScript
70 lines
2.1 KiB
JavaScript
|
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;
|
||
|
let op = form.selected.options[index].textContent;
|
||
|
let res = "";
|
||
|
|
||
|
function chooseOperation(oper){
|
||
|
switch(oper){
|
||
|
case "+":
|
||
|
return "sum"
|
||
|
case "-":
|
||
|
return "diff"
|
||
|
case "*":
|
||
|
return "mul"
|
||
|
case "/":
|
||
|
return "div"
|
||
|
case "%":
|
||
|
return "ost"
|
||
|
case "con":
|
||
|
return "con"
|
||
|
}
|
||
|
}
|
||
|
|
||
|
let operstor = chooseOperation(op)
|
||
|
if(form.num2.value == 0) return;
|
||
|
res = await fetch(`http://localhost:8080/${operstor}?num1=${form.num1.value}&num2=${form.num2.value}`)
|
||
|
res = await res.text();
|
||
|
|
||
|
// switch(op) {
|
||
|
// case "+":
|
||
|
// res = await fetch(`http://localhost:8080/sum?num1=${form.num1.value}&num2=${form.num2.value}`)
|
||
|
// res = await res.text();
|
||
|
// break;
|
||
|
// case "-":
|
||
|
// res = await fetch(`http://localhost:8080/diff?num1=${form.num1.value}&num2=${form.num2.value}`)
|
||
|
// res = await res.text();
|
||
|
// break;
|
||
|
|
||
|
// case "*":
|
||
|
// res = await fetch(`http://localhost:8080/mul?num1=${form.num1.value}&num2=${form.num2.value}`)
|
||
|
// res = await res.text();
|
||
|
// break;
|
||
|
|
||
|
// case "/":
|
||
|
// if(form.num2.value == 0) return;
|
||
|
// res = await fetch(`http://localhost:8080/div?num1=${form.num1.value}&num2=${form.num2.value}`)
|
||
|
// res = await res.text();
|
||
|
// break;
|
||
|
|
||
|
// case "%":
|
||
|
// if(form.num2.value == 0) return;
|
||
|
// res = await fetch(`http://localhost:8080/ost?num1=${form.num1.value}&num2=${form.num2.value}`)
|
||
|
// res = await res.text();
|
||
|
// break;
|
||
|
|
||
|
// case "con":
|
||
|
// res = await fetch(`http://localhost:8080/con?num1=${form.num1.value}&num2=${form.num2.value}`)
|
||
|
// res = await res.text();
|
||
|
// break;
|
||
|
// }
|
||
|
|
||
|
form.res.value = res;
|
||
|
}
|