Problem getting API data to display for Local Weather App

I’m working on the Local Weather App. I can’t seem to get the JSON data to display on my page. I’m not sure whether it’s because it’s simply not connecting to the API, or whether it’s a problem with my code (more likely the second). Here is a link to my project on CodePen:

And here is my HTML code:

<div class="container-fluid">
    <div class="row text-center">
          <h1>L<i class="wi-day-sunny"></i>cal Weather</h1>
    <div class="row text-center">
      <span class="city">city</span>
      <span class="country">country</span>
    <div class="row text-center">
      <span class="temperature">C/F</span>
    <div class="row text-center">
      <span class="weather">weather type</span>
    <div id="data"></div>

Here is my Javascript code:

const ROOT_URI = "";

  if (navigator.geolocation) {
    // temp toggle here! 
  } else {
    $("#data").html("Sorry! Your browser does not support geolocation");
    console.log("Sorry! Your browser does not support geolocation.");

function fetchWeather(lat, lon) {
  const lat = "lat=" + position.coords.latitude;
  const lon = "lon=" + position.coords.longitude;
  const uri = `${ROOT_URI}${lat}&${lon}`;
  $.getJSON(uri, function(json){
    $(".city").html( + ", ");
    currentTempInCelsius = Math.round(result.main.temp * 10) / 10;
    $(".temperature").html(currentTempInCelsius + " " + String.fromCharCode(176));

Thank you in advance for any suggestions on how to fix this.

Check your browser’s console (Ctrl+Shft+J in Chrome) and you will see the following error message:

Uncaught SyntaxError: Identifier ‘lat’ has already been declared

You can not declare a variable with const if you have already declared it via a parameter.

Also, not sure why you have two parameters (lat, long) for your fetchWeather function. It should only have one parameter (i.e. position), because the response from the avigator.geolocation.getCurrentPosition call is a Position object. You will figure this out, when you try to reference position.coords.latitude and get a reference error, because position does is not declared.

Thank you so much. I didn’t realize that const could not be used if it had already been declared in a parameter. After those changes, the API is working.

You also need to define tempUnit before using it in $("#tempunit").html(tempUnit);