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 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.

            
              <h1>Free Code Camp Zipline</h1>


<p>local Weather App</p>
<div id="weatherpic">
 
</div>  
<div class="row">
  <div id="region" class ="stats">
    <p id="location" class="stats"></p>
    <p id="temp" class="stats" ></p>
    <p id="desc" class="stats"></p>
  </div>
  <div class="city" id="wind">
    <i class="wi wi-cloudy"></i>
    <span class="weather-temp cloud">Wind</span>
  </div>
  <div class="city" id="sunrise">
    <i class="wi wi-day-sunny"></i>
    <span class="weather-temp">Sunrise</span>
  </div>
  <div class="city" id="sunset">
    <i class="wi wi-day-haze"> </i>
    <span class="weather-temp">Sunset</span>
  </div>
  <div class="city" id="humidity">
    <i class="wi wi-humidity"></i>
    <span class="weather-temp">Humidity</span>
  </div>


</div>


<button id="changeTmp" type="button" class="btn btn-primary">Display: °F / °C</button>
</div>
            
          
!
            
              
h1{
     font-family: 'Buda', cursive;
      font-size:4em;
}
p{
  font-family: 'Open Sans',Arial,Helvetica,Sans-Serif;
  font-size:1.4em;
  }
body{
text-align:center;
background: url("http://54.152.253.14/hostedImages/OIj4uAF.jpg")no-repeat center center fixed;
 -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}


.temp{
    color:red;
  
}
#desc{
   font-family: 'Buda', cursive;
  
  
}
.weather-temp{
    font-size:1.5em;
    color:black;
    font-family: 'Buda', cursive;
    font-weight:bold;
 }
.title{
  color:#15111E;
  font-size:2.4em;
  font-family: 'Open Sans',Arial,Helvetica,Sans-Serif;
   font-weight:bold;
  
}
.city{
  width:160px; 
  height:100px;
	background:#FFF;
  opacity: 0.6;
  border-radius:8px;
  padding-right:150px;
 
   padding-right:0px;   
   display:inline-block;

  
}
#region{
  width:20%;
	height:140px;
	background:#FFF;
	margin:40px auto;
  opacity: 0.6;
  border-radius:8px;
  color:black;
  font-weight:bold;
  
}
.weather-font{
  color:black;
  font-size:1.8em;
  font-align:center;
  padding-top:24px;
  font-family: 'Buda', cursive;
  font-weight:bold;
  padding-top:10px;
}
#changeTmp{
margin-top:100px;  
}
@media (max-width:767px) {
  h1{
    font-size:30px;
    
  }
  .stats{
    
    font-size:10px;
    
  }
  p{
    
    font-size:10px;
    
  }
  .city{
      width:auto;
      height:auto;
    
  }
 #region{
  width:42%;
	height:110px;
	background:#FFF;
	margin:40px auto;
  opacity: 0.6;
  border-radius:8px;
  color:black;
  font-weight:bold;
  
}

}
            
          
!
            
              $(document).ready(function() {
 var night = false;
  var backgroundImg = ["https://i.imgur.com/OIj4uAF.jpg", "https://i.imgur.com/CItHj28.jpg"];

  var changeIcon = function(desc){
    console.log(desc)
    
	   
      date = new Date();
    
      var sunrise = convertTime (desc.sys.sunrise);
      var localTime = moment(new Date);
      var endTime = moment(sunset, 'h:mma');

       var sunset = convertTime (desc.sys.sunset); 
    console.log(sunset); 
    console.log(localTime) // here
     
     console.log(desc.sys.sunrise < desc.sys.sunset )
       
       var timeStr = date.toLocaleTimeString();
    
         var sunsetGmt =Date.parse('20 Aug 2000 '+sunset);
            
        var currentTime  = Date.parse('20 Aug 2000 '+timeStr);
    console.log(sunset)
         
if(desc.sys.sunrise > desc.sys.sunset){
   night = true;
 
  $('body').css('background-image','url(http://54.152.253.14/hostedImages/night.jpg)')
   $('h1').css('color','#B8B3B3');
   $('body').css('background-image','url(http://54.152.253.14/hostedImages/night.jpg)')
   $("p:first").addClass("title");
  
}



 
  var weatherPtrn = ['clear sky','clouds','rain','thunderstorm','snow','mist'];

    result = false;
    var counter = 0;
    while(result !== true){
       
        patt = new RegExp(weatherPtrn[counter]);

         result = patt.test(desc.weather[0].description);
          counter++
        var img =  counter;
      
      
    
    img--;
    }
   var dayTime = '<img id="theImg" src="http://54.152.253.14/hostedImages/vclouds_weather_icons_by_vclouds-d2ynulp/'+img+'.png"/>';

var nightTime ='<img id="theImg" src="http://54.152.253.14/hostedImages/night_weather/'+img+'.png"/>';
    
    if(night == true){
        $('#weatherpic').prepend(nightTime);
       
    } else{
      
    $('#weatherpic').prepend(dayTime);
    }
   
  };  
  
  var convertTime = function(sec) {

     var date = new Date(sec * 1000);
    var timeStr = date.toLocaleTimeString();
    //timeStr = timeStr.split(' ').shift();
    return timeStr;
  }

  var tempChange = function() {

    var tmp = $("#temp").text();

    var patt = new RegExp("F");

    var result = patt.test(tmp);

    if (result === true) {

      var Fah = tmp.replace(/[°F]/g, "");
      var cel = Math.round((Fah - 32) / 1.8);

      $('#temp').html('<p class="text-center temp">' + cel + '&degC' + '</p>');
    } else {
      Fah = tmp.replace(/[°C]/g, "");

      Fah = Math.round((Fah * 1.8) + 32);
      $('#temp').html('<p class="text-center temp">' + Fah + '&degF' + '</p>');

    }

  }

  var getLocation = function() {

    return $.getJSON({
      url: 'https://ipinfo.io'
    });

  };

  var setLocation = function(locObj) {
   
    locObj.done(function(data) {
      
       var lat = data.loc.split(',')[0];
        var lon = data.loc.split(',')[1];
     var weatherJson = $.getJSON({
        url: 'http://api.openweathermap.org/data/2.5/weather?lat='+lat+'&lon='+lon+'&units=imperial&APPID=f06621c969f661953c1fff5012294280'
      });
  
      weatherJson.done(function(weatherObj) {
     
        $("#location").html('<p class="weather-temp">' + data.city + ',' + data.region + '</p>');
        $('#temp').html('<p class="text-center temp">' + weatherObj.main.temp + '&degF' + '</p>');
        $('#desc').html('<p class="text-center desc">' + weatherObj.weather[0].description + '</p>');
        var sunrise = convertTime(weatherObj.sys.sunrise);
        
        var sunset = convertTime(weatherObj.sys.sunset);
        
        $('<p class="text-center desc">' + sunrise + '</p>').appendTo("#sunrise");
        $('<p class="text-center desc">' + sunset + '</p>').appendTo("#sunset");
        $('<p class="text-center desc">' + weatherObj.wind.speed + '</p>').appendTo("#humidity");
        $('<p class="text-center desc">' + weatherObj.main.humidity + '</p>').appendTo("#wind");
        var imgSrc =  changeIcon(weatherObj);
      });

    });

  };
  $("#changeTmp").click(tempChange);

  var locationJson = getLocation();
  setLocation(locationJson);

});
            
          
!
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.
Loading ..................

Console