freeCodeCamp: Show the Local Weather

In this example below you will see how to do a freeCodeCamp: Show the Local Weather with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by rhapsodyjoy, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright rhapsodyjoy ©

Technologies

  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>freeCodeCamp: Show the Local Weather</title>
  
  
  
  
  
</head>

<body>

  <head>
</head>

<body>
  <header>
  </header>
  <p id="thing1"></p>
  <p id="thing2">Hello!</p>
</body>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/rhapsodyjoy/freecodecamp-show-the-local-weather-LOyXYN */
var x = document.getElementById("thing1");
var y = document.getElementById("thing2");
var lat, lon;

function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      lat = position.coords.latitude;
      lon = position.coords.longitude;

      x.innerHTML = "Latitude: " + lat + "<br>Longitude: " + lon;

      $.getJSON(
        "https://fcc-weather-api.glitch.me/api/current?lat=" +
          lat +
          "&lon=" +
          lon,
        function(data) {
          var items = [];
          $.each(data, function(key, val) {
            items.push("<li id='" + key + "'>" + val + "</li>");
          });

          $("<ul/>", {
            class: "my-new-list",
            html: items.join("")
          }).appendTo("body");
        }
      );
    });
  }
}

getLocation();

Comments