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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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="box text-center">
    <h1>Show the Local Weather</h1>
    <h3>Front End Developer Project</h3>
    <hr>
    <ul class ="list-unstyled">
      <li class ="btn btn-default" id="city"></li>
      <li id = "weatherIcon"></li>
      <li class ="btn btn-default" id = "weatherType"></li>
      <li class ="btn btn-default" id="temp"></li>
      <li class ="btn btn-default" id = "windSpeed"></li>
    </ul>
  </div>

            
          
!
            
              body {
  background-size: cover;
}

.box {
  background: rgba(00, 00, 00, 0.4);  /* Black background with 40% opacity */
  width: 500px;
  height: 400px;
  margin: 10% auto;
  padding: 50px 0;
  color: white;
}

.weatherIcon {
  
}
            
          
!
            
              $(document).ready(function() {
  var long;
  var lat;
  
  $.getJSON("https://ipapi.co/json/",function(data2){
    lat=data2.latitude;
    long= data2.longitude;
  
    // API URL with geolocation
    var api = 'http://api.openweathermap.org/data/2.5/weather?lat=' + lat + '&lon=' + long + '&appid=20f9701230babdc5f5b826bc30da9ccd';

    $.getJSON(api, function(data) {
      var fTemp;
      var cTemp;
      var kTemp;
      var iconNo;
      var tempSwap = true;

      // JSON call for Open Weather API
      var weatherMain = data.weather[0].main;
      var weatherType = data.weather[0].description;
      var weatherIcon = data.weather[0].icon;
      var windSpeed = data.wind.speed;
      var city = data.name;

      // Temperture in Kelvin
      kTemp = data.main.temp;
      // Temp in F
      // Show in HTML:  &#8457;
      fTemp = (kTemp*(9/5)-459.67).toFixed(1);
      // Temp in C
      // Show in HTML:  &#8451;
      cTemp = (kTemp-273).toFixed(1);
      // Change Wind Speed from meters to miles per hour
      windSpeed = (2.237*(windSpeed)).toFixed(1);
      
      // Create Icon number from weatherIcon
      iconNo = weatherIcon.substring(0,2);

      $("#lonlat").html("latitude: " + lat + "<br>longitude: " + long);
      $("#iconNo").html(iconNo);
      $("#city").html(city);
      $("#weatherType").html(weatherType);
      $("#weatherMain").html(weatherMain);
      $("#weatherIcon").html("<img src=http://openweathermap.org/img/w/" + weatherIcon + ".png>");
      $("#temp").html(fTemp + " &#8457;");
      $("#temp").click(function() {
        if (tempSwap === false) {
          $("#temp").html(fTemp + " &#8457;");
          tempSwap = true;
        } else {
          $("#temp").html(cTemp + " &#8451;");
          tempSwap = false;
        }
      });

      $("#windSpeed").html(windSpeed + " mph");

      if (iconNo === "01") { // clear sky
        $('body').css('background-image', 'url("https://scontent-mia1-2.xx.fbcdn.net/v/t1.0-0/p206x206/12928188_10209399007997587_2767001881760304014_n.jpg?oh=2731a8c616af321401344f21bb5ebdd5&oe=58B355E8")');
      } else if (iconNo === "02") { // few clouds
        $('body').css('background-image', 'url("https://lh3.googleusercontent.com/REntxI3Ryw7IVYafbalSyk1yBPtJlXx69soMBkjQaLqNZ1ICM8sCpqv7SbHEgGjP_7B6-GOjoowsLXHpevfDSBI-GVuFGLRyXBEMzX5ItnG3EqO8bbqvfGxP5BxGYP3I4tDiIZ3KTonOzjRNQxZSMQ5sPQAeAtKpKTRWeNGYD-lTgvWXJjpnNLqVmiOZS1sTJ9DKhTcxqg9A8hvRjtB_kxG4Moot_xeDLUJ5pud07vxsST-DQbCRkBCk-C-azD5YHgdMqfcST0Rkf33E4y4XI_SoY5bzYiak6xYPCArxg1DiQT1DGKQun0uTYtlWbe4SjFIVUI0DllGAnOQcD_wguZKyZ96KIteRueZIbQ_9J3HoseM7yWDJx2ZA3ODxcvWxXsa-zRew5-NwZPjLw_gFwWHlXfX3X5I1bgoNKEAnxPlo0eORRlnWjCp3ygvxvEHFi5Tb5L6dRo8oMY6ya_xGcttbJLUGEjaMHEpofnCsyc_zrvhxgdHquGiPEVdJfjRe8iVReHkn-GSE3iRCl1QoR-91mdY5049gmJIVqwYm7u_kplPCOtFLPDAS1s_e3Z7ufmeNnJpRcH3sxwnxikToliUSt5h23lN7TB9eC27tHPG2-uxhc58=w1097-h731-no")');
      } else if (iconNo === "03") { // scattered clouds
        $('body').css('background-image', 'url("https://lh3.googleusercontent.com/sh_BqaeBAhkEB5tC_5woN76qgbhIajtSUTt0F7eQ3Hct5AGUFH82HK4_HcKkniJa1ldCxU0rbcBx3SamlROcB5Mk9mFBskhXw9MJsvFmaYOq6k7n7VGf_LBw-rOo6FtaULB3vVqUTpq0vJTCJDc3fNI6OMCl9A1hgMi86ldeVy3HbUXDqgvJIO-L05I3dTANC-xpK9UD-cG8EHmHKRD196cRWI0IMTRBu9j5R60vYZNw2CNer_DjXG9Aqzd1_GnU7mRkCb0_6SLyPcLQEbtX0nwZPL0eFNRLN9yKrHOFTrjbmAi4rYu9qrtyTx8jZX1vX40CQv0-sgeFfnWdUSd2N12-q_WQB33YNAKCNx9UxgJFHeLVMlRinRNMTZdHb_N1HD2cMvHXQT0ev8ssZbYae00Xlne46MCGyvGpbdLNaiU4UQK9sY9lz5ojPljSLcyDnhFvERrCAfW7gcyWjsbfuKampCSCiHZKDlXoZIOeYjIThZRcS03_OkGbFq9o2CaTsZ9rQy_6v2bhXbUlKUA-QzOA9aLEvD3IfoAr1m3C-kHxTMUjedUWYS8Yx2u45tM7aSW_PFOM_U5z_mvk4srr93PHhR-qT4M0IMnG24A3KJWZbiw=w1097-h731-no")');
      } else if (iconNo === "04") { // broken clouds
        $('body').css('background-image', 'url("http://www.vanderbilt.edu/travelfellowship/blogs/russell/wp-content/uploads/DSC01587.jpg")');
      } else if (iconNo === "09") { // shower rain
        $('body').css('background-image', 'url("http://wallpapercave.com/wp/ZwhP4fb.jpg")');
      } else if (iconNo === "10") { // rain
        $('body').css('background-image', 'url("http://wallpapercave.com/wp/tHUebMB.jpg")');
      } else if (iconNo === "11") { // thunderstorm
        $('body').css('background-image', 'url("http://wallpapercave.com/wp/2aVHHg1.jpg")');
      } else if (iconNo === "13") { // snow
        $('body').css('background-image', 'url("https://1.bp.blogspot.com/-npeXt42RMeU/Vg7SczeZjXI/AAAAAAAAFgU/RJuI0aAkbWQ/s1600/6999941-beautiful-snow-path.jpg")');
      } else if (iconNo === "50") { // mist
        $('body').css('background-image', 'url("http://cdn.wallpapersafari.com/27/84/Ksduob.jpg")');
      } else {
        $('body').css('background-image', 'url("https://scontent-mia1-2.xx.fbcdn.net/v/t1.0-0/p206x206/12928188_10209399007997587_2767001881760304014_n.jpg?oh=2731a8c616af321401344f21bb5ebdd5&oe=58B355E8")');
      }
    });
  });
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console