Are you attempting to update the content of your #text
element with the result of test(x,y)? To achieve this, you would typically use code similar to:
const answer = test(x,y);
document.getElementById('idOfThingToBeChanged').innerHTML = answer;
If you want this action to occur when a button is clicked on your page, you should include this code within your event listener, like so:
document.getElementById('idOfThingToBeClicked')
.addEventListener('click', () => {
// (the code above)
});
If X and Y are values obtained from elements in your HTML page, you can retrieve them as follows:
const x = document.getElementById('idOfElement1').value;
const y = document.getElementById('idOfElement2').value;
const answer = test(x, y);
This will lead to your final solution resembling something like:
document.getElementById('elementToBeClicked')
.addEventListener('click', () => {
const x = document.getElementById('idOfElement1').value;
const y = document.getElementById('idOfElement2').value;
document.getElementById('elementToBeChanged')
.innerHTML = test(x, y);
});
//Make sure to add this code after the page has loaded
I hope this explanation covers all aspects, but feel free to reach out if you need further assistance.