123

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.

            
              <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>
            
          
!
            
              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;
}
            
          
!
            
              //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
🕑 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.

Console