Get Geolocation Data to Find a USER

Tell us what’s happening:
Describe your issue in detail here.

hi how can I complete this part from the code
You should display the user’s position within the div element with id="data"

  **Your code so far**
// Add your code below this line

if (navigator.geolocation) {

navigator.geolocation.getCurrentPosition(function(position) {

  $("#data").html("latitude: " + position.coords.latitude + "<br>longitude: " + position.coords.longitude);



// Add your code above this line
<h4>You are here:</h4>
<div id="data">
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36 Edg/101.0.1210.53

Challenge: Get Geolocation Data to Find A User’s GPS Coordinates

Link to the challenge:

HI @frab !

This lesson provides you with the exact code to copy and paste into the lesson.
Your current code here is missing the getElementById() method and innerHTML. These methods are going to access the element with the id of data and set this portion in the html

"latitude: " + position.coords.latitude + "<br>longitude: " + position.coords.longitude

I would reset the lesson and use the code they gave you.

Also, you can learn more about the methods mentioned from the docs.

yes in fact on the side of the element

should I need to create then a var location = document.getElementById(‘data’)
and then the code or let position … I mean Im learning in fact in other lessons I just do that copy and paste but alse read the instructions I tryed to understan what Im doing but for me it imposible to understand tha part o the instruction I mean You should display the user’s position within the div element with id="data" I just dont get it

Let’s break down the code they gave you here

if (navigator.geolocation){
  navigator.geolocation.getCurrentPosition(function(position) {
    document.getElementById('data').innerHTML="latitude: " + position.coords.latitude + "<br>longitude: " + position.coords.longitude;

If this is true

if (navigator.geolocation)

Get the current location of the user


Access the element that has an id of data


and set its html using innerHTML


to this content here

"latitude: " + position.coords.latitude + "<br>longitude: " + position.coords.longitude

What we are doing here is dynamically adding content to the HTML markup using javascript.
You don’t need to touch this part here at all

JavaScript is getting information from the user and adding that content to the div element using innerHTML.

Hope that is clearer.

I will be analyze as deep as I can code its hard but I think as everything once you get involve for a while things are getting more familiar thank you soo much

1 Like

It is normal for it to take a while to get used to.
But with more practice the concepts will start to make more sense. :+1:

1 Like

in fact let me ask one little question about this topic, cause I feel like Im doing wrong here, but I dont see another way on how to do it cause Im learning alone I mean, I dont have no one telling me what to do I thing :crazy_face:, but if I read the instructions and try to understand then of course its normal to copy and paste and see how the code works right… cause its to much info … but I will never stop I promise Im getting in love about coding in fact Im in love hahahha thanks again

Yes, it can be hard when you are self taught.
But I would advise you to continue to ask questions on concepts you don’t understand and lean away from copying the code first.

Also, I noticed that in your post history, you seem to be jumping around to different sections of the curriculum a lot.
I would strongly advise you to follow the linear path that fcc setup so you can develop a strong foundation in the fundamentals and become stronger in solving these problems yourself.

Hope that helps!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.