I am using Geoapify to get customer location by IP, I want to change "href" after that depending on the location. This is what I am doing to get the location
var requestOptions = { method: 'GET', };
var obj;
fetch("https://api.geoapify.com/v1/ipinfo?&apiKey=API_KEY", requestOptions)
.then(response => response.json())
.then(result => obj = result)
.then(() => console.log(obj))
.catch(error => console.log('error', error));
after that, I want to do something like that to change the href inside a tag
if (obj.country.name="United Arab Emirates"){
var strLink = "URL";
document.getElementById("cam-link").setAttribute("href",strLink);
} else if (obj.country.name="Saudi Arabia"){
var strLink = "URL";
document.getElementById("cam-link").setAttribute("href",strLink);
}else{
var strLink = "URL";
document.getElementById("cam-link").setAttribute("href",strLink);
}
but javascript always execute the if condition before fetching the response, so it doesn't work, can someone help me with that please?