Pibd-22_Emelyanov_A.S._IP/frontend/script.js

26 lines
726 B
JavaScript
Raw Normal View History

2023-02-19 15:53:42 +04:00
'use strict'
let num1 = document.getElementById("input1")
let num2 = document.getElementById("input2")
let operator = document.getElementById("operator")
let result = document.getElementById("result")
function FindOperator(operat){
let OperatorVal = operat
switch(OperatorVal){
case "+": return "add"
case "-": return "subtract"
case "/": return "divide"
case "*": return "multiply"
}
}
function calculate(){
let number1 = num1.value
let number2 = num2.value
let oper = FindOperator(operator.value)
fetch(`http://localhost:8080/${oper}/${number1}/${number2}`)
.then(response => response.text())
.then(data => {result.value = data})
}