41 lines
944 B
JavaScript
41 lines
944 B
JavaScript
|
function setResult(result) {
|
||
|
let lbl = `<label class="bg-success">Ответ:${result}</label>`;
|
||
|
document.getElementById("result").innerHTML = lbl;
|
||
|
}
|
||
|
let addButton = document.getElementById("getResultAdd");
|
||
|
let a = document.getElementById("addNum1");
|
||
|
let b = document.getElementById("addNum2");
|
||
|
let Output = document.getElementById("addAnswer");
|
||
|
let address = "hello"
|
||
|
function add(){
|
||
|
address = "add"
|
||
|
executeRequest();
|
||
|
}
|
||
|
function sub(){
|
||
|
address = "sub"
|
||
|
executeRequest();
|
||
|
}
|
||
|
function mul(){
|
||
|
address = "mul"
|
||
|
executeRequest();
|
||
|
}
|
||
|
function del(){
|
||
|
|
||
|
address = "del"
|
||
|
if(b.value != 0) executeRequest();
|
||
|
|
||
|
}
|
||
|
|
||
|
function executeRequest() {
|
||
|
|
||
|
let num1 = a.value;
|
||
|
let num2 = b.value;
|
||
|
console.log("a" + num1 + "b" + num2)
|
||
|
fetch(`http://localhost:8080/${address}?a=${num1}&b=${num2}`)
|
||
|
.then(response => {
|
||
|
return response.json();
|
||
|
})
|
||
|
.then(result => {
|
||
|
setResult(result);
|
||
|
})
|
||
|
}
|