Weather App isn't working... Can someone help me understand why?

Weather App isn't working... Can someone help me understand why?
0

#1

Here is my code:

var lat, lon

function getLocation(position) {
  lat = position.coords.latitude;
  lon = position.coords.longitude;
}

function noLocation() {
  document.getElementById("#data").innerHTML = "";
  alert("Sorry, we can not find your location.");
} 

function setElement(data) {
  document.getElementById("#data").innerHTML = data;
}

function getWeather() {
  if (lat && lon) {
    var apiKey = "2db9452f6f5d46d554721c08bfe1ab13";
    var url = "https://api.darksky.net/forecast/";
    var cors = "https://cors-anywhere.herokuapp.com/";
    //var full = cors + url + apiKey + "/" + lat + "," + lon + "?exclude=currently,hourly,flags";
    //var full = cors + url + apiKey + "/" + lat + "," + lon;
    var full = url + apiKey + "/" + lat + "," + lon;
    $.getJSON(full + "output=jsonp&callback=?", setElement);
  }
}

$(document).ready(function () {
  //unsupported browser alert
  if (!navigator.geolocation) {
    alert("Your Browser does not support Geolocation, sorry!")
  }

  else {
    navigator.geolocation.getCurrentPosition(getLocation, noLocation);  
         
    //click-event handler
    $("#weatherbtn").click(getWeather);
  }
});

#2

Link to my Codepen: https://codepen.io/MissLisaMN/pen/owBKeQ Please note this is still very much a work in progress…


#3

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

Can you post a link to your codepen? Have you checked your browser console for errors?


#5

Sure! Edited my first reply to add my link, Thanks, btw.