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.

+ add another resource

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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.

+ add another resource

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console