function setResult(result) { let lbl = ``; 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); }) }