To make a request to the API and calculate on the result would look something like this:
function makeRequest() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
calcPreco(xmlHttp.responseText);
}
xmlHttp.open("GET", "PONHA_SUA_URL_AQUI", true); // true para asynchronous
xmlHttp.send(null);
}
function calcPreco(preco) {
preco = preco.replace(",", ".");
preco -= 5;
document.getElementById("result").textContent = preco;
}
To recover the price that is in a url parameter would look something like this:
function calcPreco(){
let preco = new URL(location.href).searchParams.get("get");
preco -= 5;
document.getElementById("result").textContent=preco;
}
If you receive a number with ,
in the parameter (something like 10,50
) do:
function calcPreco(){
let preco = new URL(location.href).searchParams.get("get");
preco = preco.replace(",", ".");
preco -= 5;
document.getElementById("result").textContent=preco;
}