123

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 class="container-fluid">

    <div class="row bits-row2 justify-content-center">
		<div class="col-md-9">
			<div class="row justify-content-between">
        
				<div class="col-md-5 text-left align-self-center bits-row2col1">
					<h2><span id="city"></span>,</h2>
					<h2><span id="country"></span></h2>
				</div>
      
				<div class="col-md-3 text-center align-self-center bits-row2col2">
					<h1 class="display-4"><span id="tempCelsius"></span></h1> 
				</div>
      
				<div class="col-md-4 text-right align-self-center bits-row2col3">
					<h3 id="toggleUnit"><i class="fa fa-plane"></i> ~ <span id="toggleUnitText">&deg;C | &deg;F</span></h3>
				</div>

			</div>
		</div>
    </div>
	
	<div class="row bits-row3 justify-content-around">
		<div class="col-md-8">
			<div class="row justify-content-center">
    
				<div class="col-md-8 text-center">
					<h2>Weather is...</h2>
					<p class="display-4"><span id="weather"></span></p>
					<p class="lead">...<span id="weatherDesc"></span></p>
				</div>
				
				<div class="col-md-4 text-center">
					<h2 class="display-4"><span class="weatherIconGroup" id="weatherIcon"></span></h2>
				</div>
      
			</div>
		</div>
	</div>
  
	<div class="footer text-center lead"> by <a href="https://codepen.io/bitscaa/">Bitscaa</a></div>
	
</div>


            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Raleway:400,500);
@import url(https://fonts.googleapis.com/css?family=Lobster:400,500);
 
body {
  background: url("http://www.vectortiles.com/wp-content/uploads/eco-friendly-patterns-06-600x600.jpg") center center;
  /* background: url("http://www.vectortiles.com/wp-content/uploads/sky-and-cloud-patterns-08-600x600.jpg") center center; */
  font-family: "Roboto Light";
  margin: 2.5em auto 2.5em auto;
  /* padding: 0 2.5em 0 2.5em; */
  color: white;
  
}

.bits-row1, .bits-row2, .bits-row3 {
  margin: auto 2.5em auto 2.5em;
  margin-bottom: 2.5em;
}

.bits-row1 div {
	/* changed to footer */
}

.bits-row2 div {
  background-color: #01010F;
  opacity: 0.9;
  padding-left: 0.4em;
  padding-right: 0.4em;
  margin-left: auto;
  margin-right: auto;
  padding-top: 0.5em;
  padding-bottom: 0.5em;
  border-radius: 1em;
}

.bits-row2col1 {
  font-family: "Raleway";
  overflow-wrap: break-word;
}

.bits-row2col2 {
  font-family: "Lobster";
  overflow-wrap: break-word;
}

.bits-row2col3 {
  font-family: "Raleway";
  overflow-wrap: break-word;
}

.bits-row3 div {
  font-family: "Lobster";
  background-color: #01010F;
  opacity: 0.9;
  padding-left: 0.4em;
  padding-right: 0.4em;
  margin-left: auto;
  margin-right: auto;
  padding-top: 0.5em;
  padding-bottom: 0.5em;
  border-radius: 1em;
}

#toggleUnitText {
  color: grey;
}

#toggleUnitText:hover {
  color: brown;
  cursor: pointer;
}

#weatherIconImg {
	width: 2.5em;
	height: 2.5em;
}

.footer, .footer * {
  font-family: "Lobster";
/*   background-color: #0F0F0F; */
  color: black;
}

            
          
!
            
              
// var ipInfoAPI = 'http://ipinfo.io/json?callback=JSON_CALLBACK';

var city = '';
var country = '';
var units = 'metric'
var appID = '061f24cf3cde2f60644a8240302983f2';
var weather = '';
var weatherDesc = '';
var weatherIconURL = 'http://openweathermap.org/img/w/';
var tempCelsius = 0;
var tempFahrenheit = 0;
var currentUnit = 'celsius';


function getWeather() {
	
	$.ajax({
		dataType: 'jsonp',
		url: 'https://ipinfo.io/',
    // url: 'http://ip-api.com/json',
		type: 'GET',
		data: {},
		success: function(responseGeo) {
			// var rGeo = JSON.parse(responseGeo);
			var rGeo = responseGeo;
			city = rGeo.city;
			country = rGeo.country;
			console.log(city);
			
			  $.ajax({
				url: 'http://api.openweathermap.org/data/2.5/weather?q=' + city + '&units=' + units + '&appid=' + appID,
				type: 'GET', // The HTTP Method, can be GET POST PUT DELETE etc
				data: {}, // Additional parameters here
				dataType: 'json',
				success: function(response) {
				  // var r = JSON.parse(response);
				  var r = response;
				  weather = r.weather[0].main;
				  weatherDesc = r.weather[0].description;
				  weatherIconURL += r.weather[0].icon + '.png';
				  tempCelsius = Math.round(r.main.temp);
				  
				  console.log(weather);
				  console.log(tempCelsius);
				  
					tempFahrenheit = Math.round(r.main.temp * 9/5 + 32);
					console.log(tempFahrenheit);

					$("#city").html(city);
					$("#country").html(country);
					$("#tempCelsius").html(tempCelsius + "&deg;C");
					$("#weather").html(weather);
					$("#weatherDesc").html(weatherDesc);
					$("#weatherIcon").html('<img class="img-fluid" id="weatherIconImg" src="' + weatherIconURL + '">');
					// $(".weatherIconGroup").html('<img class="img-fluid" id="weatherIconImg" src="' + weatherIconURL + '">');
					
					console.log(weatherDesc);
				  
				  
					// switch (r.weather[0].icon) {
						// case "10d":
						// case "10n":
							// $("#weatherIcon").html('<i class="wi wi-rain" id="weatherIconImg"></i>');
							// break;
						// case "04d":
						// case "04n":
							// $("#weatherIcon").html('<i class="wi wi-cloudy" id="weatherIconImg"></i>');
							// break;
					// }				  

				},
				error: function(err) {
				  alert(err);
				}

			  });
			
		},
		error: function(err) {
		  alert(err);
		}
	});
	

}

getWeather();

$(document).ready(function() {
	
	$("#toggleUnitText").on("click", function(){
		
	  switch (currentUnit) {
		case 'celsius': 
			currentUnit = "fahrenheit";
			$("#tempCelsius").html(tempFahrenheit + "&deg;F");
			$("#toggleUnitText").html("in &deg;C"); 	
			break;
		case 'fahrenheit':
			currentUnit = "celsius";
			$("#tempCelsius").html(tempCelsius + "&deg;C");
			$("#toggleUnitText").html("in &deg;F")
			break;
	  }
	  
	});
	
});



            
          
!
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