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.

            
              <!--FreeCodeCamp.com Zipline task demo of a local weather app.  It uses two api queries to gather local information, and display the local weather conditions. Code by Suzanne Atkinson(@adventurebear), styling by Julie Myers (@blueoceanview)  on freecode.slack.com

Other resources:  
Country Codes for imperial vs. metric check: 
http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes

List of countries that use fahrenheight:
http://en.wikipedia.org/wiki/Fahrenheit
-->



<link href='https://fonts.googleapis.com/css?family=Lato:400,700' rel='stylesheet' type='text/css'>

<div id="title">Free Code Camp Zipline</div>
<div id="subtitle">Local Weather App</div>

 <!--<div id="loadingGif"></div>-->

<div id="iconTemp">
 <div id="icon"></div>
 <div id="temp"></div>
</div>  

<div id="weatherWrapper">
 <div class="location details"></div>
 <div id="conditions" class="details"></div>
 <div id="wind" class="details"></div>
  <div id="postal"></div>
</div>  

<!--<button>Convert Units</button>-->
  
            
          
!
            
              
html{
  font-size: 18px;
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: url("http://static.pexels.com/wp-content/uploads/2014/06/clouds-colorful-colourful-1029.jpg") no-repeat;
  background-size: cover;
}

body {
  font-family: 'Lato', sans-serif;
  text-align: center;
  font-size: 1em;
}

#title{
  font-size: 1.8em;
  padding: 1%;
  color: #BFAD61;
  text-shadow: 0 0 0.3em #000;
}

#subtitle{
  font-size: 1.5em;
  margin-bottom: 3%;
  color: #BFAD61;
  text-shadow: 0 0 0.3em #000;
}


#loadingGif {
  display: block;
  margin:0 auto;
  height: 32px;
  width: 32px;
  background-image: url("https://i.imgur.com/g6fBUAd.gif");
}


#icon, #temp{
  display: inline-block;
}

img{
  vertical-align: middle;
}

#icon{
  position: relative;
  bottom: 5px;
}

#temp{
  font-size: 1.8em;
  font-weight: bold;
  padding-bottom: 1%;
  color: #ffffff;
  text-shadow: 0 0 0.2em #333;
}

.location, #conditions, #wind{
  display: inline-block;
}

.details{
  border: 2px solid #ffffff;
  color: #7F3320;
  padding: 2% 1% 2% 1%;
  margin: 0 auto 0.7% auto; 
  background-color: #ffffff;
  border-radius: 0.3em;
  box-shadow: .2em .2em .2em #444;
  opacity: 0.7;
}

#postal {
  font-size: 1.8em;
  font-weight: bold;
  padding-top: 3%;
  color: #ffffff;
  text-shadow: 0 0 0.2em #333;
}

button{
  margin-top: 3%;
  font-size: 1.15em;
  border: 0.1em solid #ffffff;
  border-radius: 0.2em;
  background-color: #7F3320;
  color: #ffffff;
  padding: 0.5%;
}

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

  getLocation();

  function getLocation() {
    $.get("http://ipinfo.io", function(location) {
      console.log(location);
      
      $('.location')
        .append(location.city + ", ")
        .append(location.region);

      var units = getUnits(location.country);
      getWeather(location.loc, units);

      //return weather;

    }, "jsonp");

  }

  function getWeather(loc, units) {
    lat = loc.split(",")[0] //.toString();
    lon = loc.split(",")[1] //.toString();

    //var weatherApiUrl = 'http://api.openweathermap.org/data/2.5/weather?lat=' + lat + '&lon=' + lon + "&units=" + units;
    var weatherApiUrl = 'http://api.openweathermap.org/data/2.5/weather?lat=' + lat + '&lon=' + lon + "&units=" + units + '&appid=e2db5b0453a25a492e87ad8b03046a7c';

    console.log(weatherApiUrl);

    $.get(weatherApiUrl, function(weather) {
      var windDir = convertWindDirection(weather.wind.deg);
      var temperature = weather.main.temp;
      var unitLabel;

      //label based in imperial vs metric units
      if (units === "imperial") {
        unitLabel = "F";
      } else {
        unitLabel = "C";
      }

      temperature = parseFloat((temperature).toFixed(1));

      console.log(weather);

      $('#icon')
        .append("<img src='http://openweathermap.org/img/w/" + weather.weather[0].icon + ".png'>");

      $('#temp').append(temperature + " " + unitLabel);
      $('#conditions').append(weather.weather[0].description);
      $('#wind').append(windDir + " " + weather.wind.speed + " knots");
      $('#postal').append(postal);

    }, "jsonp");

  };

  function convertWindDirection(dir) {
    var rose = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'];
    var eightPoint = Math.floor(dir / 45);
    return rose[eightPoint];
  }

  function getUnits(country) {
    var imperialCountries = ['US', 'BS', 'BZ', 'KY', 'PW'];

    if (imperialCountries.indexOf(country) === -1) {
      var units = 'metric';
    } else {
      units = 'imperial';
    }

    console.log(country, units);
    return units;
  }

});
            
          
!
999px
Loading ..................

Console