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

              
                <html>
<meta charset = "utf-8">
<link href="https://fonts.googleapis.com/css?family=Great+Vibes" rel="stylesheet"> 
<style>

body{
	  background-image: url("https://wandervogeldiary.files.wordpress.com/2014/11/let-the-sunshine-in-l-xwvssr.jpeg");
    background-size: cover;
    background-repeat: no-repeat;
}

div {
	
    color: white;
    background: gray;
    width: 60%;
    margin: auto;
    border-radius: 5px;
    padding: 10px;
    opacity: 0.5;
    border: solid white 2px;
    
}

p{
	text-align: center;
}

h1 {
	font-family: 'Great Vibes', cursive;
    font-size: 30px;
    text-align: center;
    color: white;
}
  h2 {
    text-align: center;
    font-size: 30px;
    color: white;
  }
  
  button{
    padding: 10px 5px 3px 5px;
  }


</style>
<body>
<h1>
Welcome back and
<script language="JavaScript"> 
var myDate = new Date(); 
  
if ( myDate.getHours() < 12 ){ 
   	document.write("Good Morning!"); 

} 
else if ( myDate.getHours() >= 12 && myDate.getHours() <= 17 ){ 
    document.write("Good Afternoon!"); 
} 
else if ( myDate.getHours() > 17 && myDate.getHours() <= 24 ) { 
    document.write("Good Evening!"); // 6pm to midnight
 
} 
else  /* the hour is not between 0 and 24, so something is wrong */
{ 
    document.write("I'm not sure what time it is!"); 
} 
  


</script> 
  </h1>
  
<div class = container-fluid>
<h1 id = "currentLocation"></h1>
 <h2 id = "currentTemp"></h2>
  <h2 id = "toggle">&#8451</h2>
  <h2 id = currentWeather></h2>
  <h2 id = "highTemp-lowTemp"></h2>
  </div>

</body>

</html>
              
            
!

CSS

              
                <style>

body{
	  background-image: url("https://wandervogeldiary.files.wordpress.com/2014/11/let-the-sunshine-in-l-xwvssr.jpeg");
    background-size: cover;
    background-repeat: no-repeat;
}

div {
	
    color: white;
    background: gray;
    width: 60%;
    margin: auto;
    border-radius: 5px;
    padding: 10px;
    opacity: 0.5;
    border: solid white 2px;
    
}

p{
	text-align: center;
}

h1 {
	font-family: 'Great Vibes', cursive;
    font-size: 30px;
    text-align: center;
    color: white;
}
  h2 {
    text-align: center;
    font-size: 30px;
    color: white;
  }
  
  button{
    padding: 10px 5px 3px 5px;
  }


</style>
              
            
!

JS

              
                var API_KEY = "e72689f19281323eb01051d541492e13";
var celsius = false;
var weatherData;

var weatherImage = "";
  var imagePhoto = {
	thunder: "https://s-media-cache-ak0.pinimg.com/originals/2e/43/73/2e4373184057ab029b5ca15aca484b09.jpg",
	rainyNight: "https://s3.envato.com/files/32036621/rainy-night-window-pr.jpg",
    rainy: "https://c1.staticflickr.com/1/25/44040866_f74b3a3fd3_b.jpg",
	cloudy: "https://static1.squarespace.com/static/57523357c2ea515ccf6c1adb/58dcea75bebafb06e997da9c/58dcece61e5b6cf38585d46b/1490873606398/mostly+cloudy.jpg",
    cloudyNight: "https://hatterkep.kepek-hatterkepek.hu/221/2213461.jpg",
	snow: "https://static.bhphotovideo.com/explora/sites/default/files/Correct.jpg",
	clear: "https://mota.ru/upload/wallpapers/2010/05/14/08/01/22099/mota_ru_0051405-2560x1600.jpg",
  clearNight: "https://dncache-mauganscorp.netdna-ssl.com/thumbseg/1615/1615594-bigthumbnail.jpg",
	drizzle: "https://s-media-cache-ak0.pinimg.com/736x/e4/43/f5/e443f59b4f03dd487d090a279c2f08ab--rain-drops-water-drops.jpg",
    drizzleNight: "https://c1.staticflickr.com/8/7482/15859210528_7fc3e7fcd6_b.jpg",
	haze: "https://ak3.picdn.net/shutterstock/videos/3578564/thumb/1.jpg",
  hazeNight: "https://farm4.static.flickr.com/3023/2801417308_82e8f25367.jpg",
	tornado: "https://i.ytimg.com/vi/5QnsRXUbsK4/maxresdefault.jpg",
	cold: "https://static.pexels.com/photos/374/snow-dawn-sunset-winter.jpg",
	windy: "https://ak9.picdn.net/shutterstock/videos/4337360/thumb/1.jpg",
  windyNight: "https://s-media-cache-ak0.pinimg.com/736x/ea/5c/03/ea5c035613ecb1852fd9189eb61673ee--beach-at-night-on-the-beach.jpg",
	hail: "https://s-media-cache-ak0.pinimg.com/236x/7c/60/3d/7c603d9183ff32c92330780a2ebdcfca--rainy-weather-rainy-days.jpg",
  sunny: "https://i.ytimg.com/vi/rG9fev-m0ag/maxresdefault.jpg"
};


function selectImage (id) {
    if (id >= 200 && id <= 232){
		weatherImage = imagePhoto.thunder;
	}else if (id >= 300 && id <= 321){
		weatherImage = imagePhoto.drizzle;
	}else if (id >= 500 && id <= 531){
		weatherImage = imagePhoto.rainy;
	}else if (id >= 600 && id <= 622){
		weatherImage = imagePhoto.snow;
	}else if (id >= 701 && id <= 721 ){
		weatherImage = imagePhoto.haze;
	} else if (id === 800){
		weatherImage = imagePhoto.clear;
	}else if (id >= 801 && id <= 804){
		weatherImage = imagePhoto.cloudy;
	}else if (id >= 900 && id <= 902){
		weatherImage = imagePhoto.tornado;
	}else if (id === 903){
		weatherImage = imagePhoto.cold;
	}else if (id === 904){
		weatherImage = imagePhoto.sunny;
	}else if (id === 905){
		weatherImage = imagePhoto.windy;
	}else if (id === 906){
		weatherImage = imagePhoto.hail;
	}else{
		weatherImage = imagePhoto.windy;
  }
  $('body').css('background-image', 'url(' + weatherImage + ')'); 
} 

if (myDate.getHours() > 17 && myDate.getHours() <= 24){
  function selectImage(id){
    if (id >= 200 && id <= 232){
      weatherImage = imagePhoto.thunder;
	}else if (id >= 300 && id <= 321){
		weatherImage = imagePhoto.drizzleNight;
	}else if (id >= 500 && id <= 531){
		weatherImage = imagePhoto.rainyNight;
	}else if (id >= 600 && id <= 622){
		weatherImage = imagePhoto.snow;
	}else if (id >= 701 && id <= 721 ){
		weatherImage = imagePhoto.hazeNight;
	}else if (id === 800){
		weatherImage = imagePhoto.clearNight;
	}else if (id >= 801 && id <= 804){
		weatherImage = imagePhoto.cloudyNight;
	}else if (id >= 900 && id <= 902){
		weatherImage = imagePhoto.tornado;
	}else if (id === 903){
		weatherImage = imagePhoto.coldNight;
  }else if (id === 905){
		weatherImage = imagePhoto.windyNight;
	}else if (id === 906){
		weatherImage = imagePhoto.hail;
	}else{
		weatherImage = imagePhoto.windyNight;
	}
	$('body').css('background-image', 'url(' + weatherImage + ')');
}
}

     
function displayTemp(fTemp, c){
  if (c) return Math.round((fTemp - 32) * (5/9)) + "&#8451";
  return Math.round(fTemp) + "&#8457";
}

function render(weatherData, celsius){
  var currentLocation = weatherData.name;
      var currentWeather = weatherData.weather[0].description;
      var currentTemp = displayTemp(weatherData.main.temp, celsius);
      var highTemp = displayTemp(weatherData.main.temp_max, celsius);
      var lowTemp = displayTemp(weatherData.main.temp_min, celsius);
      var icon = weatherData.weather[0].icon;
      
      $('#currentLocation').html(currentLocation);
      $('#currentTemp').html(currentTemp);
      $('#currentWeather').html(currentWeather);
      $('#highTemp-lowTemp').html(highTemp + "/" + lowTemp);
      
      
      var iconSrc = "http://openweathermap.org/img/w/" + icon + ".png";
      $('#currentTemp').prepend('<img src="' + iconSrc + '">');
      
  
}
$(function(){
  
  var loc;
  $.getJSON('https://ipinfo.io', function(d) {
    console.log("assigning data here...")
    loc = d.loc.split(",");
    console.log(loc);
    
    $.getJSON('https://api.openweathermap.org/data/2.5/weather?units=imperial&lat='+ loc[0] + '&lon=' + loc[1] + '&APPID=' + API_KEY, function(apiData){
      weatherData = apiData;
      var id = weatherData['weather'][0]['id']; 
	  
      render(apiData, celsius);
      $('#toggle').click(function(){
        celsius = !celsius;
        render(weatherData, celsius);
			})
      selectImage(id);
		})
   
	})
})
        
              
            
!
999px

Console