Solution doesn't work: User's position within the data div element

Tell us what’s happening:
Hello everyone!

When I submit my code, it always returns this message: “You should display the user’s position within the data element.”

Well, I’m seeing the user’s position in the screen and I used the getElementById('data') to access the data element.

So what am I doing wrong?

PS.: In this GitHub issue, people already had the same problem in the past

Your code so far


<script>
if(navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(function(position) {
    document
      .getElementById("data")
      .innerHTML = 
        "latitude: " + position.coords.latitude +
        "<br>longitude: " + position.coords.longitude
  })
}
</script>
<h4>You are here:</h4>
<div id="data">

</div>

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36.

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

Link to the challenge:
https://www.freecodecamp.org/learn/data-visualization/json-apis-and-ajax/get-geolocation-data-to-find-a-users-gps-coordinates

1 Like

Hello,

The problem seems to be that your code is not on a single line, but the validator expects a single line.

And don’t forget the semicolon at the end of the line (I know it’s not required for JavaScript in general, but sometimes the validator is too strict :stuck_out_tongue:).

1 Like

Thank you skaparate! It worked here :smiley:

About the semicolon, you’re right. It’s a simple thing we don’t pay attention now, but may cause problems in the future. I’ll be more carefully

1 Like