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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

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.

HTML

            
              <div class = "container-fluid jumbotron">
  <div class = "text-center">
    <p><button onclick="getGeo()">Get current weather</button></p>
    <h1>Tim's</h1>
    <h1>Weather App</h1>
    <h2>
      <span class = "place">Place</span>, <span class = "country">Country</span>
    </h2>
    <h3>
      <div class = "temp">
        Current temperature
      </div>
      <div class = "condition">
        Current condition
      </div>
    </h3>
  </div>  
</div>
            
          
!

CSS

            
              .container-fluid {
  width: 50%;
  margin-top: 20px;
}

body {
  background-color: grey;
}
            
          
!

JS

            
              var place = document.querySelector("span.place");
var country = document.querySelector("span.country");
var temp = document.querySelector(".temp");
var condition = document.querySelector(".condition");
var latitude = 0;
var longitude = 0;
// http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139&appid=c3274763022ab2757a62ce204ce0b818
// Use the API key

function getWeather() {
  // getGeo(); // get the location first
  // console.log("Longitude is " + longitude);
  // console.log("Latitude is " + latitude);
  var URL = "http://api.openweathermap.org/data/2.5/weather?lat=" + latitude + "&lon=" + longitude + "&appid=c3274763022ab2757a62ce204ce0b818";
  
  $.getJSON(URL, function(data){
    place.textContent = data.name;
    country.textContent = data.sys.country;
    console.log("The city name is: " + data.name);
    console.log("The country name is: " + data.sys.country);
  });
};

function getGeo() {
  if ( window.chrome ) {
    $.getJSON('http://ip-api.com/json', function(data) {
      latitude = data.lat;
      longitude = data.lon;
      getWeather();
    });
  } else {
    if (!navigator.geolocation){
      // alert("Geolocation is not supported");
      return
    };  
    function success(position){

      latitude = position.coords.latitude;
      longitude = position.coords.longitude;
      console.log("Longitude is " + longitude);
      console.log("Latitude is " + latitude);
      getWeather();
    };  
    function error(){
      // alert("Geolocation is not supported");
    };  
    navigator.geolocation.getCurrentPosition(success, error);
  }
}
            
          
!
999px

Console