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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                <header>
  <h1>Your Local Forecast</h1>
  <h3>By Natac</h3>
</header>

<div class="weather">
  <div class="description"></div>
  <div id="temp"></div>
  <button type="button" id="units" class="flag">&#8451; / &#8457;</button>
  <div class="icon"></div>
  <div class="wind-dir"></div>
</div>

<p class="location"></p>
              
            
!

CSS

              
                html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #333;
  background-size: cover;
}

body {
  font-family: "Trebuchet MS", Helvetica, sans-serif;
  text-align: center;
  font-size: 1.5em;
  color: #FFA375;
}

h1, h3 {
  padding: 0;
  margin: 0;
  text-shadow: 3px -3px 2px #330A00;
}

.weather {
  border-radius: 5px;
  color: #A31919;
  background-color: rgba(255, 223, 184, 0.23);
  margin-right: auto;
  margin-left: auto;
  width: 40%;
  margin-top: 50px;

}

.description {
  margin-left: 25px;
}

.temp {
  margin-right: 25px;
  font-weight: bold;
}

.icon {
  margin: 20px;
  padding: 0;
}
.description, .temp {
  display: inline-block;
  font-size: 1em;
  padding: 0;
  text-shadow: 1px -2px 3px #332D25;
}

.wind-dir {
  font-size: .9em;
  margin: ;
  padding-bottom: 5px;
  text-shadow: 1px -2px 3px #332D25;
  
}

#units {
  border-radius: 13px;
  padding: 5px 13px 5px 13px;
  margin: 0;
  color: #1F1F2E;
  font-size: .65em;
  font-family: "Lucida Console", Monaco, monospace;
  box-shadow: 3px -3px 5px #32324B;
  font-weight: bold;
}

button.flag {
  background: linear-gradient(to right, red, white, red);
}

button {
  background: linear-gradient(150deg, white, blue, white, red, white, red);
}







              
            
!

JS

              
                $(document).ready(function() {
  var $weatherdiv = $('.weather');
  var $description = $('.description');
  var $temp = $('#temp');
  var $icon = $('.icon');
  var $wind_dir = $('.wind-dir');
  var $location = $('p.location');
  var $units = $('#units');

  if ("geolocation" in navigator) {
    navigator.geolocation.getCurrentPosition(success, fail);
  } else {
    alert("Sorry, but your browser is not down with this action.");
  }

  function setWindDirection(degrees) {
    if (degrees <= 22.5 || degrees >= 337.5) { // input will be larger than zero less than 360
      return "N";
    }
    if (degrees > 22.5 && degrees < 67.5) {
      return "NE";
    }
    if (degrees >= 67.5 && degrees <= 112.5) {
      return "E";
    }
    if (degrees > 112.5 && degrees < 157.5) {
      return "SE";
    }
    if (degrees >= 157.5 && degrees <= 202.5) {
      return "S";
    }
    if (degrees > 202.5 && degrees < 247.5) {
      return "SW";
    }
    if (degrees >= 247.5 && degrees <= 292.5) {
      return "W";
    }
    if (degrees > 292.5 && degrees < 337.5) {
      return "NW";
    }
  }

  function setSpeed(meter_sec) {
    return +(meter_sec * 1.94384).toFixed(2);
  }

  function setTemp(kelvin) {
    var celsius = +(kelvin - 273.15).toFixed(1);
    var fah = +(celsius * (9 / 5) + 32).toFixed(2);
    return fah;
  }

  function capFirst(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
  }

  function getWeatherInfo(api) {
    $.getJSON(api, function(data_obj) {
      console.log('hello');
      var group = data_obj.weather[0].main;
      var icon = "<img src='http://openweathermap.org/img/w/" + data_obj.weather[0].icon + ".png' width=100px height=100px>";
      var temp = setTemp(data_obj.main.temp);
      var wspeed = setSpeed(data_obj.wind.speed);
      var wdir = setWindDirection(data_obj.wind.deg);
      var des = capFirst(data_obj.weather[0].description) + " with a temperature of: ";
      var city = data_obj.name;
      var country;

      $location.html("City: " + "<strong>" + city + "</strong>");
      $description.html(des);
      $temp.html(temp + " &#8457;");
      $icon.html(icon);
      $wind_dir.html("<p>" + wdir + " &commat; " + wspeed + " knots</p>");
    });
  }

  function success(position) {
    var lat = position.coords.latitude;
    var long = position.coords.longitude;
    var weatherAPI = "http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + long;

    
    getWeatherInfo(weatherAPI);

  }

  function fail(err) {
    /* Prompt section
    var city = prompt("Please enter the name a city");
    var country = "";
    var x = true
    while(country.length !== 2) { 
      var country = prompt("Enter 2 chars country code. ex - us,uk,cd"); 
    }
    var weatherAPI = "http://api.openweathermap.org/data/2.5/weather?q=" + city + "," + country;
    */
    var ip, lati, longi, weatherAPI;
    $.getJSON("http://www.telize.com/geoip?", function(json) {
      ip = json.ip;
      lati = json.latitude;
      longi = json.longitude;
      weatherAPI = "http://api.openweathermap.org/data/2.5/weather?lat=" + lati + "&lon=" + longi;
      getWeatherInfo(weatherAPI);
    });
  }

  $('#units').click(function() {
    $(this).toggleClass('flag');
    var num = parseFloat($temp.text());
    if ($temp.hasClass('cel')) {
      $temp.toggleClass('cel');
      var fah = +(num * (9 / 5) + 32).toFixed(2);
      $temp.html(fah + " &#8457;");
    } else {
      $temp.toggleClass('cel');
      var cel = +((5 / 9) * (num - 32)).toFixed(2);
      $temp.html(cel + " &#8451;");
    }
  });

});
              
            
!
999px

Console