Same as @Sanchit Gupta.
in this part
if (results[0]) {
var add= results[0].formatted_address ;
var value=add.split(",");
count=value.length;
country=value[count-1];
state=value[count-2];
city=value[count-3];
x.innerHTML = "city name is: " + city;
}
just console the results array
if (results[0]) {
console.log(results[0]);
// choose from console whatever you need.
var city = results[0].address_components[3].short_name;
x.innerHTML = "city name is: " + city;
}