Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <link href="https://fonts.googleapis.com/css?family=Quicksand" rel="stylesheet">

<div class="container-fluid text-center inclose">
   <h1> Your current weather!</h1>
   <div id="cityName">
   </div>
   <div id="weather">
   </div>
  <div id="temp"></div>
  <div id="realFeel"></div>
  <div id ="convert">
    <button class="btn btn-primary"  id="conversion">Convert to F/C</button>
  </div>
</div>
              
            
!

CSS

              
                body {
  background-image: url("");
  background-position: fixed;
  background-size: cover;
  background-repeat: no-repeat;
  letter-spacing: 5px;
  font-family: 'Quicksand', sans-serif; 
}

.inclose {
  background-color: black;
  opacity: 0.5;
  color: white;
}

div {
  padding-top: 20px;
  padding-bottom: 20px;
  font-size: 180%;
}

#realFeel {
  font-size:100%;
}

.btn {
  background-color: transparent !important;
}

.btn:hover {
  font-size: 20px;
}
              
            
!

JS

              
                //get the address from the IP Geolocation API
function getLocation() {
  $.getJSON("http://ip-api.com/json", function(loc){
    $("#cityName").text(loc.city + ', ' + loc.regionName + ', ' + loc.country)
    getWeather(loc.lat, loc.lon);
  })
    .fail(function(err) {
    getWeather()
  });
}

getLocation();

//Retreive temperature details from openweathermap.org using longitude and latitude from previous API
function getWeather(lat, lon) {
var apiAddress = "http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&units=imperial&type=accurate&APPID=9d4a841a5b68f2cc43c97d5224e11086";
  $.getJSON(apiAddress, function (weatherData){
    
    tempF = weatherData.main.temp.toFixed(0);
    tempC = ((tempF- 32)*(5/ 9)).toFixed(0);
    weather = weatherData.weather[0].description;
   
    windMPH= weatherData.wind.speed;
    windKPH = (windMPH*1.6).toFixed(0);
    
    realFeelImperial = (windMPH/tempF).toFixed(0);
    realFeelMetric = (windKPH/tempC).toFixed(0);
    
  $("#weather").text(weather + ', Wind speed: ' + windMPH + ' mph');
    $("#temp").text('Temperature:' + tempF + '°F');
    $("#realFeel").text('Real-Feel Temperature:' + realFeelImperial + '°F');
    
    var bodyImages = {'clear sky' : 'https://media.giphy.com/media/l3vRoeR8KaNNs3g88/giphy.gif',
                  'clear night' : 'https://media.giphy.com/media/SE5Qvze2QBpbq/source.gif', 
                  'few clouds' : 'https://media.giphy.com/media/o6qaN00DUo7x6/giphy.gif',
                  'few clouds night' : 'https://media.giphy.com/media/R19AHAAwMnEpa/giphy.gif',
                  'scattered clouds' : 'https://media.giphy.com/media/qZMonv0Jty1P2/giphy.gif',
                  'night scattered clouds' : 'https://media.giphy.com/media/afuXKLnDHbb8I/giphy.gif',
                      'overcast clouds': 'https://media.giphy.com/media/l5hH6uglWfetW/giphy.gif',
                  'broken clouds' : 'https://s-media-cache-ak0.pinimg.com/originals/58/25/32/58253287ef7d5f5bccc3490d64017ffd.jpg',
                  'night broken clouds' : 'http://www.troyjohnstone.com/astrophotography/images/sky_clouds_night_moon_2006_09_09_04.jpg',
                  'shower rain' : 'https://media.giphy.com/media/oaNFVNEcvWv5K/giphy.gif',
                  'night shower rain' : 'https://s-media-cache-ak0.pinimg.com/originals/52/07/68/5207680e1eafd7233ab094b5f910e6af.gif',
                  'rain' : 'https://media.giphy.com/media/BAD9hUGYZkqPe/giphy.gif',
                  'light rain' : 'http://umad.com/img/2015/6/night-rain-gif-9410-9796-hd-wallpapers.jpg',
                  'thunderstorm' : 'https://media.giphy.com/media/8xY1YYpEZ4dws/giphy.gif',
                  'night thunderstorm' : 'https://media.giphy.com/media/8xY1YYpEZ4dws/giphy.gif',
                  'snow' : 'https://media.giphy.com/media/RCEi2dX26vfi/giphy.gif',
                  'light snow' : 'https://media.giphy.com/media/LbMTeG6A2VbDa/giphy.gif',
                  'mist' : 'https://media.giphy.com/media/xT8qBgwBouvNofiuuA/giphy.gif',
                  'night mist' : 'https://media.giphy.com/media/ofrQ8FYfTD8gE/giphy.gif' };

    $("body").css("background-image", "url(\" " + bodyImages[weather] + " \")");
            });
}
//to convert celcius into farenheit using data from earlier function.
    $("#conversion").click(function() {
      if($("#temp").text().indexOf('F') > -1) {
        $("#temp").text('Temperature: ' + tempC + '°C');
        $("#weather").text(weather + ', Wind speed: ' + windKPH + ' kph');
        $("#realFeel").text('Real-Feel Temperature:' + realFeelMetric + '°C');
      }
      
      else {
         $("#temp").text('Temperature: ' + tempF + '°F');
        $("#weather").text(weather + ', Wind speed: ' + windMPH + ' mph');
        $("#realFeel").text('Real-Feel Temperature:' + realFeelImperial + '°F');
      }
    })


              
            
!
999px

Console