cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="container text-center">
  <div class="row justify-content-center">
    <div class="col-md-6">
      <h1> Free C❄de Camp</h1>
      <h1> Weather App</h1>
      <h4><span class="city">City</span>, <span class="country">Country</span></h4>
      <h4><span class="temperature">Temp</span>℃</h4>
      <h4><span class="description">Description</span></h4>
      <h4>
    </div>
  </div>
</div>
            
          
!
            
              /*
 * Author: Vincent Tang
 * Date Created: !(12/17/2017 22:15)
 * --------------------
 * https://stackoverflow.com/questions/47842732/javascript-unexpected-run-order, I had async issues with navigator.geolocation
 * https://stackoverflow.com/questions/47853190/javascript-access-json-property - I had issues accessing a property, as it was an array of objects
 */

body {
  background-color: black;
  color: white;
}

            
          
!
            
              $(document).ready(function(){

  // Navigator.geolocation is Async, see SO#
  if (navigator.geolocation){
    navigator.geolocation.getCurrentPosition(function(position){
      let curLat = "lat=" + position.coords.latitude;
      let curLon = "lon=" + position.coords.longitude;
      let weatherAPI = getURL(curLon, curLat);
      
      //Access JSON data
      $.getJSON(weatherAPI, function(data){
        let curCity = data.name;
        let curCountry = data.sys.country;
        let curTemp = Math.round(data.main.temp*10)/10; //13.3
        let curDescription = data.weather[0].description //weather is array of Obj, see SO#
        $('.city').html(curCity);
        $('.country').html(curCountry);
        $('.temperature').html(curTemp);
        $('.description').html(curDescription);
      });
    });
  } 
});

//Make URL for API request
function getURL(lon, lat){
  var url =  "https://fcc-weather-api.glitch.me/api/current?";
  url = url + lon + "&" + lat;
  return url;
}
            
          
!
999px
Loading ..................

Console