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.

            
              <section class="weather">
  <div id="city"></div>
  <img src="http://www.placehold.it/350x350" name="pic" alt="Weather corresponding with the type outside">
  <p>
    <span class="weather__temperature change-temperature" id="temp"></span>
    <br>
    <span class="weather__type" id="type"></span>
  </p>
</section>

<footer>
  <span>
    <p>
    &copy;2016 Dave Regg
    </p>
    Geolocation from <a href="http://freegeoip.net" target="_blank">FreeGeoIP</a> //
    <br>
    Powered by <a href="http://openweathermap.org/api" target="_blank">Weather App</a> //
    <br>
    Images courtesy of <a href="https://openclipart.org/" target="_blank">Open Clipart</a>
  </span>
</footer>

<!-- OLD
<header class="header hide">
  <h1 class="header__text header__text--primary">Local Weather App</h1>
</header>
-->
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Yellowtail');

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -ms-box-sizing: border-box;
  -o-box-sizing: border-box;
}

body {
  text-align: center;
  font-family: Verdana;
  font-size: 14px;
  margin: 0 auto;
  background: #2ECC71;
  color: #181818;
}

img {
  width: 250px;
  margin: 1em 0;
  padding: 1em;
  border: 5px solid #00993E;
  border-radius: 5px;
  background: #eee;
  box-shadow: 0 5px 10px #004D00;
}

p {
  font-size: 1.5em;
  line-height: 1.5em;
}

/* -------------------- *\
\* ----- WEATHER ------ */

.weather {
  margin: 2.5em auto;
}

.weather h2 {
  font-size: 2.5em;
  font-weight: normal;
  font-family: 'Yellowtail', cursive;
  letter-spacing: .05em;
  /*text-shadow: 1px 1px 10px #004D00;*/
}

.weather__temperature {
  font-size: 3em;
  line-height: 1.5em;
}

.change-temperature {
  cursor: pointer;
}
.change-temperature:hover {
  color: #E3548D;
}

.weather__type {
  text-transform: capitalize;
}

/* -------------------- *\
\* ------ FOOTER ------ */

footer {
  padding: 5em 0;
  font-size: .65em;
}

footer a {
  color: #E3548D;
}
footer a:hover {
  text-decoration: none;
}

/* -------------------- *\
\* ------ HELPER ------ */

.hide {
  display: none;
}

/* --------------------- *\
\* ------ DESKTOP ------ */

@media only screen and (min-width: 992px) {
  .weather h2 {
    font-size: 4em;
  }
  .weather>div br,
  footer br {
    display: none;
  }
  
  img {
    margin: 4.5em 0;
    width: 450px;
  }
  
  footer {
    font-size: .75em;
  }
}


/*
* {
  box-sizing: border-box;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -ms-box-sizing: border-box;
  -o-box-sizing: border-box;
}

body {
  text-align: center;
  font-family: Verdana;
  font-size: 14px;
  margin: 0 auto;
  background-color: #C63D0F;
}

.weather {
  background-color: #FDF3E7;
  margin: 5em 20em;
  padding: 1em 0;
  box-shadow: 0 5px 5px #333;
}
.weather__text {
  text-transform: capitalize;
  padding: .5em 0;
  color: #3B3738;
}
.weather__text--header {
  font-size: 250%;
  font-family: 'Yellowtail', cursive;
}
.weather__text--normal {
  font-size: 150%;
}
.weather__text--temperature {
  font-size: 250%;
  font-weight: bold;
  padding: 0;
  color: #FDF3E7;
  text-shadow:
    -2px -2px 0 #3B3738,
    -2px 2px 0 #3B3738,
    2px -2px 0 #3B3738,
    2px 2px 0 #3B3738;
}

.weather__text--clickable {
  cursor: pointer;
  color: #7E8F7C;
}
.weather__text--clickable:hover {
  text-decoration: underline;
  color: #4B5C49;
}

img {
  margin: 2em auto;
  width: 250px;
}

.footer {
  background-color: #FDF3E7;
  /*box-shadow: 0 -5px 5px #333;
}
.footer__text {
  padding: 5em 0;
  margin: 0;
  font-size: .75em;
  color: #3B3738;
}
.footer__text--clickable {
  color: #7E8F7C;
}
.footer__text--clickable:hover {
  color: #4B5C49;
  text-decoration: underline;
}

@media only screen and (max-width: 320px) {
  body {
    font-size: 1em;
    background-color: #FDF3E7;
  }
  .weather {
    width: 100%;
    margin: 1em 0;
    padding: 0;
    background-color: #FDF3E7;
    box-shadow: none;
  }
  .footer {
    width: 100%;
    background-color: #C63D0F;
  }
}

.hide {
  display: none;
}

OLD
.header {
  background-color: #FDF3E7;
  box-shadow: 0 5px 5px #333;
}
.header__text {
  padding: 1em 0;
  margin: 0 auto;
  width: 100%;
}
.header__text--primary {
  font-size: 300%;
  color: #3B3738;
  font-weight: bold;
}
*/
            
          
!
            
              // Get long and lat with geolocation
// Call API
// Replace text with data
// Change image according to data
// IF statement for C / F

$(document).ready(function(){
  // Urls for Location Api and Weather Api
  var weatherApi = "http://api.openweathermap.org/data/2.5/weather?";
  // var geolocationApi = "http://freegeoip.net/json/";
  
  // Update the weatherApi Url by using the geolocationApi
  $.getJSON(geolocationApi, function(location){
    // var lat = "lat=" + location.latitude;
    // var lon = "&lon=" + location.longitude;
    var city = 'q=Philadelphia';
    var apiKey = "&appid=780062c871d1cd69decae7b5869ddeba";
    weatherApi = weatherApi + city + apiKey;
    
    
    
    // Update the City and Country HTML with the Api
    $("#city").html("<h2>Philadelphia,<br>USA</h2>");
    
    
    
    // Update the website using the weatherApi
    $.getJSON(weatherApi, function(weather){
      // Grab the description from the Api
      var weatherDescription = weather.weather[0].description;
      
      // Grab the temperature from the Api and convert to F and C
      var fahrenheitTemperature = Math.floor((weather.main.temp * (9/5)) - 459.67);
      var celsiusTemperature = Math.floor(weather.main.temp - 273.15);
      var tempUnits = "&deg;C";
      
      // Grab the ID from the Api and display the image
      var weatherDescriptionId = weather.weather[0].id;
      getWeatherImage(weatherDescriptionId);
      
      
      // Update the HTML
      $("img").attr("src", weatherImage);
      $("#type").html(weatherDescription);
      $("#temp").html(celsiusTemperature + tempUnits);
      
      
      // Update #temp on click
      $(".change-temperature").on("click", function(){
        if (tempUnits === "&deg;C") {
          tempUnits = "&deg;F";
          $("#temp").html(fahrenheitTemperature + tempUnits);
        } else if (tempUnits === "&deg;F") {
          tempUnits = "&deg;C";
          $("#temp").html(celsiusTemperature + tempUnits);
        };
      });
      
      
    }); // end .getJSON weatherApi
  }); // end .getJSON geolocationApi
}); // end jQ



function getWeatherImage(id) {
  var mainWeatherDescription = "";

  // Grab the description according to the range of the Id
  if (id >= 200 && id < 300) {
    mainWeatherDescription = "thunderstorms";
  } else if (id >= 300 && id < 400) {
    mainWeatherDescription = "drizzle";
  } else if (id >= 500 && id < 600) {
    mainWeatherDescription = "rain";
  } else if (id >= 600 && id < 700) {
    mainWeatherDescription = "snow";
  } else if (id >= 700 && id < 800) {
    mainWeatherDescription = "atmosphere";
  } else if (id === 800) {
    mainWeatherDescription = "clear";
  } else if (id > 800 && id < 805) {
    mainWeatherDescription = "cloudy";
  } else if (id === 900) {
    mainWeatherDescription = "tornado";
  } else if (id === 901 || id === 902) {
    mainWeatherDescription = "hurricane";
  } else if (id === 903) {
    mainWeatherDescription = "extremeCold";
  } else if (id === 904) {
    mainWeatherDescription = "extremeHeat";
  } else {
    mainWeatherDescription = "unknown";
  }

  // Associate the Description with an image
  var weatherImageOptions = {
    thunderstorm: "https://openclipart.org/download/217034/thunderstorm.svg",
    drizzle: "https://openclipart.org/download/1474/spite-overcloud-rain.svg",
    rain: "https://openclipart.org/download/208578/Sad-Little-Cloud.svg",
    snow: "https://openclipart.org/download/204895/Cloud-snow.svg",
    atmosphere: "https://openclipart.org/download/210347/misc-mental-worry.svg",
    clear: "https://openclipart.org/download/126151/1299551682.svg",
    cloudy: "https://openclipart.org/download/21996/nicubunu-Weather-Symbols-Cloudy-Day.svg",
    tornado: "https://openclipart.org/download/104887/1295057149.svg",
    hurricane: "https://openclipart.org/download/179926/hurricane.svg",
    extremeCold: "https://openclipart.org/download/14465/h0us3s-Signs-Hazard-Warning-30.svg",
    extremeHeat: "https://openclipart.org/download/15724/Machovka-summer2-1.svg",
    unknown: "https://openclipart.org/download/22412/nicubunu-Emoticons-Question-face.svg"
  };

  // Return the image based on the description
  return weatherImage = weatherImageOptions[mainWeatherDescription];
};
            
          
!
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