IP_PIbd-21_Yakhontov_OU/front/script.js
2023-02-27 18:12:01 +04:00

42 lines
1.8 KiB
JavaScript

let calculateButton = document.getElementById("calculate");
let buttonPlus = document.getElementById("buttonPlus");
let buttonMinus = document.getElementById("buttonMinus");
let buttonMulti = document.getElementById("buttonMulti");
let buttonDiv = document.getElementById("buttonDiv");
let numberOneInput = document.getElementById("first");
let numberTwoInput = document.getElementById("second");
let resultInput = document.getElementById("res");
let typeInput = document.getElementById("type");
buttonPlus.onclick = function(event) {
let num_1 = numberOneInput.value;
let num_2 = numberTwoInput.value;
let type = typeInput.value;
fetch(`http://localhost:8080/sum?first=${num_1}&second=${num_2}&type=${type}`)
.then(response => response.text())
.then(res => resultInput.value = res);
}
buttonMinus.onclick = function(event) {
let num_1 = numberOneInput.value;
let num_2 = numberTwoInput.value;
let type = typeInput.value;
fetch(`http://localhost:8080/minus?first=${num_1}&second=${num_2}&type=${type}`)
.then(response => response.text())
.then(res => resultInput.value = res);
}
buttonMulti.onclick = function(event) {
let num_1 = numberOneInput.value;
let num_2 = numberTwoInput.value;
let type = typeInput.value;
fetch(`http://localhost:8080/multi?first=${num_1}&second=${num_2}&type=${type}`)
.then(response => response.text())
.then(response => resultInput.value = response);
}
buttonDiv.onclick = function(event) {
let num_1 = numberOneInput.value;
let num_2 = numberTwoInput.value;
let type = typeInput.value;
fetch(`http://localhost:8080/div?first=${num_1}&second=${num_2}&type=${type}`)
.then(response => response.text())
.then(res => resultInput.value = res);
}