css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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

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

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="container">
  <h1 class="text-center" id="location">Weather App</h1>
  
  <h3 class="text-center cityState" >#</h3>
  <p class="text-center weather">#</p>

  
  <p class="text-center data-nextTemp"><span style="cursor:pointer"></span></p>
</div>
  
 



            
          
!
            
              body{
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover ;
 }

#location{
  color: white;
  
}

.cityState{
  color: white;
}

.data-nextTemp{
  color: white;
  font-size: xx-large;
  
}

.weather{
  color: white;
 }

span.pointer{
  cursor: pointer;
}


  


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

  //if (window.location.protocol != 'http:') {
 // $('#error').html('This page is not supported over https yet.<br />' +
   // 'Please try again over http.');
//} else 
 // getWeather();
//}
  //Our ID key for weather app
  var appID = "&APPID=f74316dbe7442f12d602b1cae1a5172b";

  var city;
  var state;
  var fahrenheit = "&units=imperial";
  var temp;

  //using a geo-location API to get city and state info of current user
  $.getJSON('http://ip-api.com/json/?callback=?', function(data) {
    city = data.city;
    state = data.regionName;
    getWeather(city, state);

  });

  //using weather API and outputting results into our HTML
  function getWeather(city, state) {
    var api = "http://api.openweathermap.org/data/2.5/weather?q=" + city + "," + state + "" + fahrenheit + "" + appID;

    $.ajax({
      url: api,
      dataType: 'json',
      success: function(data) {
        console.log(JSON.stringify(data));
        //get condition of weather
        var weatherOut = data.weather[0].main;
        //get weather icon
        var weatherDayNight = data.weather[0].icon;
        var weatherID = data.weather[0].id;
        temp = {
          F: Math.round((data.main.temp)) + "° F",
          C: Math.round((data.main.temp - 32) * 5 / 9) + "° C"
        };
        $('h3').text(city + ", " +  state);
        $('span').html(temp['F']);
        $('.weather').text(weatherOut);

        var pickURL = weatherCond[data.weather[0].icon].cond;
        $('body').css('background-image', 'url("' + pickURL + '")');

      }
    });
  }

  $('span').on('click', function() {
    var current = $(this).data('nextTemp');
    $('span').text(temp[current]);

    if (current == 'C') {
      $(this).data('nextTemp', 'F');
      return;
    }
    $(this).data('nextTemp', 'C');
  });

  var weatherCond = {};

  weatherCond['01d'] = {
    'cond': "http://wfiles.brothersoft.com/b/blue-sky-with-clear-water_175256-1600x1200.jpg"
  };
  weatherCond['01n'] = {
    'cond': "https://web-assets.domo.com/blog/wp-content/uploads/2012/12/nighttimesky.jpeg"
  };
  weatherCond['03d'] = {
    'cond': "http://icons.wunderground.com/data/wximagenew/1/1photogirl93/29-800.jpg"
  };
  weatherCond['03n'] = {
    'cond': "http://icons.wunderground.com/data/wximagenew/1/1photogirl93/29-800.jpg"
  };
  weatherCond['04d'] = {
    'cond': "http://icons.wunderground.com/data/wximagenew/1/1photogirl93/29-800.jpg"
  };
  weatherCond['03n'] = {
    'cond': "http://icons.wunderground.com/data/wximagenew/1/1photogirl93/29-800.jpg"
  };
  weatherCond['09d'] = {
    'cond': "http://www.pureella.com/wp-content/uploads/2011/04/pleasurefeelingpeoplephotographyarm.jpg"
  };
  weatherCond['09n'] = {
    'cond': "http://alm0na.files.wordpress.com/2012/01/rain_drops_at_night-wide.jpg"
  };
  weatherCond['10d'] = {
    'cond': "http://www.pureella.com/wp-content/uploads/2011/04/pleasurefeelingpeoplephotographyarm.jpg"
  };
  weatherCond['10n'] = {
    'cond': "http://alm0na.files.wordpress.com/2012/01/rain_drops_at_night-wide.jpg"
  };
  weatherCond['11d'] = {
    'cond': "http://www.prevention.com/sites/prevention.com/files/images/news/featured_images/thunderstorm-628x363-TS-135165621_0.jpg"
  };
  weatherCond['11n'] = {
    'cond': "https://s3.amazonaws.com/rapgenius/1367403834_night-thunder-storm-lightning.jpg"
  };
  weatherCond['13d'] = {
    'cond': "https://img.buzzfeed.com/buzzfeed-static/static/2014-01/enhanced/webdr07/24/6/anigif_enhanced-buzz-2717-1390562645-0.gif"
  };
  weatherCond['13n'] = {
    'cond': "https://img.buzzfeed.com/buzzfeed-static/static/2014-01/enhanced/webdr07/24/6/anigif_enhanced-buzz-2717-1390562645-0.gif"
  };
  weatherCond['50d'] = {
    'cond': "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTNQzaAiOTFK70eqtdoaKTdMR63raFj-By0SklV6ixQPyTqt6_I"
  };
  weatherCond['50n'] = {
    'cond': "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTNQzaAiOTFK70eqtdoaKTdMR63raFj-By0SklV6ixQPyTqt6_I"
  };

});
            
          
!
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