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.

            
              <div class="container">
  <div class="jumbotron">
    <h1 class="text-center">Local Weather</h1>
    <div id=currentLocation><h2>Loading...</h2></div>
<div class="row">
  <div class="col-md-4 inner-section">
    <div id="temp"></div>
    <div id="conditions"></div>
    <div id="wind"></div>

    <div id="humidity"></div>
    <button id="converter"></button>
  </div>
    </div>
  </div>
</div> 
            
          
!
            
              body{
  background-color:#A0EE57;
}
.jumbotron{
  margin-top:10px;
  padding-bottom: 30px;
  background-color:#EBEE57;
}
.inner-section{
  border: 2px solid black;
  padding: 15px;
  margin:15px;
}
            
          
!
            
              tempF = true;

if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(function(position) {
    var longitude = position.coords.longitude;
    var latitude = position.coords.latitude;

    var siteLink = "http://api.openweathermap.org/data/2.5/weather?lat=";
    siteLink += latitude + "&lon=" + longitude + "&";
    siteLink += "&appid=b1054e6d56c8965a50894d733f264fc1";

    $.getJSON(siteLink, function(json) {
       temp = json.main.temp;
       fahrenheit = temp * 9 / 5 - 459.67; 
      
      fahrenheit = fahrenheit.toFixed(0) + "&deg F";
      celcius = temp - 273.15;
      celcius = celcius.toFixed(1) + "&deg C"
      var clouds = json.clouds.all;
      var humidity = json.main.humidity + "%";
      var cityName = json.name;
      windMS = json.wind.speed;
      var conditions = json.weather;
      
      windMPH = (windMS * 2.23694).toFixed(2);
     // windMPH = windMPH.toFixed(2);
      for(key in conditions){
        if(conditions.hasOwnProperty(key)){
           value = conditions[key];
        }
      }
      var myDescription=value.description;
      var currentConditions = value.main;
      var myDescription = value.description;
      var myIcon = value.icon;
      $('#currentLocation').html("<h2>" + cityName + "<img src='http://openweathermap.org/img/w/" + myIcon + ".png'>" + "</h2>");
 $('#temp').html(fahrenheit);
      $('#wind').html("Wind at " + windMPH + " MPH");
      $("#conditions").html(currentConditions);
      $("#humidity").html("Humidity: " + humidity);
    });
    $('#converter').html("Switch to Metric Units");

  });
} // end navigator.geolocation

$("#converter").click(function(){
  if(tempF == true){
    $("#temp").html(celcius);
    $('#wind').html("Wind at " + windMS + " m/s");
    $('#converter').html("Switch to Imperial Units");
    tempF = false;
    
  } else {
    $("#temp").html(fahrenheit);
    $('#wind').html("Wind at " + windMPH + " MPH");
    $('#converter').html("Switch to Metric Units");
    tempF = true;   
  }  
});

// $(document).ready(function(){
//   $('#converter').html("Switch to Metric Units");
// });
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console