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.

            
              <div id="container">
  <div id="title">Your local weather</div>
  <div id="city">Your location is: </div>
  <div id="coords"></div>
  <div id="temp"></div>  
  <div id="desc"></div> 
  <div id="dates"></div>
  <div id="sun"></div>
  <div id="datacalculation"></div>
    <div id="footer">Created by Sebastian Sporek</div>
</div>
            
          
!
            
              body {
  background-color:deepskyblue;
}
#container {
  width: 360px;
  margin:auto;
  background-color: lightskyblue;
  font-family: 'Lato', sans-serif;
  text-align:center;
  font-size:20px;
  color:blue;
  border:none;
  border-radius:20px;
}
#title{
  font-family: 'Luckiest Guy', cursive;
  color: white;
  font-size:32px;
  padding: 10px;
  text-align:center;  
}
#coords{
 font-size:14px;
 margin-bottom:10px;
}
#temp{  
  font-size:60px;
  padding:20px;
  padding:0;
}

#temp img{
 margin-right:20px;
}
#desc{
  text-transform:capitalize;
  padding:5px;
}
#dates{
  font-size:15px;
  text-align:left;
  width:160px;
  margin:auto;    
}
#dates ul{
  list-style-type:none;  
}
#dates ul li label{
  display:inline-block;
  width:85px;
  margin-bottom:5px;
  margin-left:-30px;
}
#sun, #datacalculation{
  font-size:16px;
}
#footer{
  padding:10px;
  font-size:10px;
  color:grey
}

button {
  width:80px;
  height:60px;
  font-size:40px;
  text-align:cenetr;
  border: 1px solid lightskyblue;
  border-radius:20px;
  margin-left:20px;
  margin-bottom:10px;
  color:blue;
  background-color:deepskyblue;
}
button:hover {
  border:1px solid blue;
  cursor:pointer;
}
#warning {
  font-size:12px;
  color:red;
  text-align:center;
  padding:5px;
}
            
          
!
            
              $(document).ready(function() {

var d = document.getElementById("#dates");
var lon;
var lat;
var data;
var json;

if ("geolocation" in navigator) {
  navigator.geolocation.getCurrentPosition(function(position) {
    lat = position.coords.latitude;
    lon = position.coords.longitude;
    lat = (Math.round(10*lat))/10;
    lon = (Math.round(10*lon))/10;
    console.log("geolocation is available",lat, lon);
    var request ="";
    var r1 = "https://cors-anywhere.herokuapp.com/http://api.openweathermap.org/data/2.5/weather?lat=";
    request = r1.concat(lat,"&lon=",lon,"&APPID=e009886c7a63f8c715c822520bdfface");
    //console.log(request);
    $.ajax({ 
      url:request,
      async:false,
      dataType:'json',
      success: function(json3) {
        json = json3;
      }});
              
      //console.log("Answer:",json);
      var longitude = json.coord["lon"];
      var latitude = json.coord["lat"];
      var temp = Math.round(json.main["temp"]-273.15);
      var tempF = Math.round((temp*1.8)+32);
      var city = json.name;
      var country = json.sys["country"];
      var description = json.weather[0].description;
      var icon = json.weather[0].icon;
      var clouds = json.clouds["all"];
      var windspeed =Math.round((json.wind["speed"]*3600)/1000);
      var pressure = Math.round(json.main["pressure"]);
      var humidity = json.main["humidity"];
      var datacalculation = json.dt;
      var sunrise = json.sys["sunrise"];
      var sunset = json.sys["sunset"];

      function convertData(datacalculation) {
        var date = new Date(datacalculation*1000);
        var hours = date.getHours();
        var minutes = "0" + date.getMinutes();
        //var seconds = "0" + date.getSeconds();
        var formattedTime = hours + ':' + minutes.substr(-2)/* + ':' + seconds.substr(-2)*/;
        return formattedTime;
       }

       var datacalculation2 = convertData(datacalculation);
       var sunrise2 = convertData(sunrise);
       var sunset2 = convertData(sunset);

      $("#city").append(city + ", "+ country);
      $("#coords").prepend("Longitude is " + longitude + " and latitude is " + latitude);
      $("#temp").append("<span class=\"show\">"+temp + " &deg;C</span>");
       $("#temp").append("<span class=\"hide\">"+tempF + " &deg;F</span>");
      $("#temp").append("<button class=\"show\" id=\"btnC\">&deg;F</button>");
       $("#temp").append("<button class=\"hide\" id=\"btnF\">&deg;C</button>");
       $(".hide").hide();

      $("#temp").prepend("<img src=\"http://openweathermap.org/img/w/" + icon + ".png \" alt=\"weather icon\">");
      $("#desc").html(description);
      $("#dates").html(
      "<ul><li><label>Clouds</label>" + clouds + " %</li>" + "<li><label>Wind speed</label>" + windspeed +" km/h</li>" +
      "<li><label>Pressure</label>" + pressure + " hPa</li>" + "<li><label>Humidity</label>" + humidity +
      " %</li></ul>");
      $("#sun").html("Today sunrise is at " + sunrise2 + " and the sunset is at " + sunset2);
      $("#datacalculation").html("Data calculation: " + datacalculation2);
       $("#btnC").click(function() {
         $(".show").hide();
         $(".hide").show();
       });

       $("#btnF").click(function() {
         $(".hide").hide();
         $(".show").show();
       });
    

  });


} else {
  $("#dates").html("Geolocation is not supported by your browser");
}
});
            
          
!
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.

Console