JSFiddle - React, Tailwind, and code Playground
JavaScript
var detectCountry = function () {
var country;
$.getJSON("http://ip-api.com/json/?callback=?", function (data) {
$.each(data, function (k, v) {
if (k == 'country') {
country = v;
}
});
});
return country;
}
var myCountry = detectCountry();
alert(myCountry);