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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <div class="container">
  <h1 class='text-center'>The current weather in you area is:</h1>
  <div class='row'>
    <div class="col-md-3"></div>
    <i aria-hidden="true"></i><div id="out" class="col-md-4 text-center"></div>
  </div>
  <label for="select">Change units:</label><select onchange="changeUnits()" id="select">
    <option value='ca'>C</option>
    <option value='us'>F</option>
  </select>
</div>
              
            
!

CSS

              
                h1 {
  margin-top: 100px;
  font-family: 'Arvo', serif;
}

#out {
  margin-top: 70px;
  font-size: 60px;
  font-family: 'Arvo', serif;
  margin-bottom: 30px;
}

label {
  font-family: 'Arvo', serif;
  font-size: 25px;
  margin-right: 5px;
}

#select {
  font-family: 'Arvo', serif;
  font-size: 25px;
  outline: none;
  background-color: #FF5F6D;
}

i {
  margin-top: 70px;
}

body {
  background: #FF5F6D;  /* fallback for old browsers */
  background: -webkit-linear-gradient(to right, #FFC371, #FF5F6D);  /* Chrome 10-25, Safari 5.1-6 */
  background: linear-gradient(to right, #FFC371, #FF5F6D); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
}
              
            
!

JS

              
                var output = document.getElementById("out");

function changeUnits(){
  navigator.geolocation.getCurrentPosition(success, error);
};

if (!navigator.geolocation){
  output.innerHTML = "<p>Geolocation is not supported by your browser</p>";
}

function success(position) {
  var latitude  = position.coords.latitude;
  var longitude = position.coords.longitude;
  
  var x = document.getElementById("select").value;

  if(x == 'ca'){
    var units = 'ca';
  } else{
    var units = 'us';
  }
  
  $.ajax({
    url: 'https://api.darksky.net/forecast/d540ec4ec68cd23b415f0e7d51026b65/'+latitude+','+longitude+'?exclude=minutely,hourly,daily,alerts,flags&units='+units,
    dataType: 'jsonp',
    crossDomain : true,
    cache: false,
    success: function(data){
      console.log(data);
      console.log(units);
      var temp = data.currently.temperature;
      if(units=='ca'){
        output.innerHTML = temp+'°C'
      } else if(units=='us'){
        output.innerHTML = temp+'°F'
      };
      var icon = data.currently.icon
      switch(icon){
        case 'clear-day':
          $('i').attr("class","fa fa-sun-o fa-5x col-md-2 text-center");
          break;
        case 'clear-night':
          $('i').attr("class","fa fa-moon-o fa-5x col-md-2 text-center");
          break;
        case 'rain':
          $('i').attr("class","fa fa-tint fa-5x col-md-2 text-center");
          break;
        case 'snow':
          $('i').attr("class","fa fa-snowflake-o fa-5x col-md-2 text-center");
          break;
        case 'sleet':
          $('i').attr("class","fa fa-snowflake-o fa-5x col-md-2 text-center");
          break;
        case 'wind':
          $('i').attr("class","fa fa-leaf fa-5x col-md-2 text-center");
          break;
        case 'fog':
          $('i').attr("class","fa fa-low-vision fa-5x col-md-2 text-center");
          break;
        case 'cloudy':
          $('i').attr("class","fa fa-cloud fa-5x col-md-2 text-center");
          break;
        case 'partly-cloudy-day':
          $('i').attr("class","fa fa-cloud fa-5x col-md-2 text-center");
          break;
        case 'partly-cloudy-night':
          $('i').attr("class","fa fa-cloud fa-5x col-md-2 text-center");
          break;
        default:
          $('i').attr("class","fa fa-question-circle fa-5x col-md-2 text-center");
      }
    },
    error: function(xhr, status, err){
      console.log(err);
    }
  });

}

function error() {
  output.innerHTML = "Unable to retrieve your location";
}

//output.innerHTML = "<p>Locating…</p>";

navigator.geolocation.getCurrentPosition(success, error);

              
            
!
999px

Console