Currently, I am utilizing the API in an attempt to retrieve an object containing both a person's city and country information. Here is my existing code:
$(document).ready(function() {
var locationAPI = "http://ip-api.com/json";
var K, C, F;
var Person = {
city: function() {
$.getJSON(locationAPI, function(data) {
return data.city;
});
},
country: function() {
$.getJSON(locationAPI, function(data) {
return data.countryCode;
});
}
};
var x = Person.city;
console.log(x); });
The current output looks like this:
function () {
$.getJSON(locationAPI, function(data) {
return data.city;
});
}
I am aiming for it to display a specific value such as - Person.country = USA. What could be the issue with my implementation?