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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


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


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.


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.


	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
	<title>Weather API</title>
	<script src=""></script>
	<script src="CallAPI.js"></script>	
	<link rel="stylesheet" href="">
	<link rel="stylesheet" href="main.css">
	<div class="container">
			<div class="row">
				<div class="col-md-12 col-xs-12">
					<h1 class=' text-center'>Check your local weather</h1>
					<h2 class="text-danger text-center">A free project by Khoa Le</h2>
					<div class="row">
					<div class="col-md-4 col-xs-4">
						<div class="well text-center ajusted" style="height: 150px;padding-top: " id="CityName">
					<div class="col-md-4 col-xs-4">
						<div class="well text-center" style="height: 150px" >
						<div class="weather-icon">
							<img  id="WeatherIcon" src="" alt="">
						<div class="temperature" >
						<p id="Temperature" data-temp="celcius"></p>
					<div class="col-md-4 col-xs-4">
						<div class="well text-center ajusted" style="height: 150px" id="ExtraInfo">



                @import url(;

	padding-top: 15%;
.well {
   background-color: rgba(245, 245, 245, 0.4);
	font-family: "Pacifico";
	color: yellow;
body {
  background-image: url(;
  position: relative;
  background-repeat: no-repeat;
  background-position: center top;
  background-size: cover;
  font-family: "Pacifico";
  min-height: 100%;
	min-height: 100%;
/*img {
  width: 100px;
  height: 100px;
	padding-right: 10%;
	padding-top: 15%;



                // get the location when the document is ready

jQuery(document).ready(function($) {
// Get the location and then get the weather when complete

function getLocation(){
// the position variable has all the location data from
	$.getJSON('', function(data) {

function getWeather(data){
 // add the lat and lon to the URL
	var url = '' + 
            'lat=' + + '&lon=' + data.lon + 

  // use getJSON with the URL above to get the weather data and study the JSON in the console to parse it

	$.getJSON(url, function(weatherData) {
		var backgroundImg = [/*0Sunnyday */'',
					/*1Rainnyday */'',
					/* 3Snow*/ '',
					/* 4Cloudday*/'',
					/* 5Thunderstorm*/''];

			var id=[0].id.toString();
			if(id>800 && id<805){
		$('body').css("background-image", 'url(' + backgroundImg[4] + ')');
		} else if(id>599 && id<623){
			$('body').css("background-image", 'url(' + backgroundImg[3] + ')');
		} else if(id>499 && id<532){
			$('body').css("background-image", 'url(' + backgroundImg[1] + ')');
		} else if(id>299 && id<322){
			$('body').css("background-image", 'url(' + backgroundImg[2] + ')');
		} else if(id>199 && id<233){
			$('body').css("background-image", 'url(' + backgroundImg[5] + ')');
		} else {
			$('body').css("background-image", 'url(' + backgroundImg[0] + ')');

    // Basic example of showing the temperature in the location

    // Return the weather description in title case
    var weather=[0].description;
    var weatherSplit = weather.split(" ");
    for (var i=0; i<weatherSplit.length; i++){
    weatherSplit[i]= weatherSplit[i].charAt(0).toUpperCase() + weatherSplit[i].slice(1).toLowerCase();	
    Weather =  weatherSplit.join(" ");
   var CelciusDegree = "<br>" + Weather + "<br>" +Math.ceil((weatherData.main.temp -32) *5/9)  + '&deg' +'C';
   var FarenheitDegree = "<br>" + Weather + "<br>" + weatherData.main.temp + ' &deg' +'F';
   var Degree = document.querySelector('#Temperature');
   Degree.setAttribute("data-temp", "celcius");
    Degree.addEventListener('click', function(e) {
      var temp = Temperature.getAttribute("data-temp");
      switch(temp) {
        case "celcius":
          Degree.innerHTML = FarenheitDegree.toString();
          Degree.setAttribute("data-temp", "farenheit");
        case "farenheit":
          Degree.innerHTML = CelciusDegree.toString();
          Degree.setAttribute("data-temp", "celcius");

	$('#CityName').append('City you are living'+ "<br>"+ + ",  " );
	$('#WeatherIcon').attr('src', ""+[0].icon + ".png");
	$('#ExtraInfo').append('Wind speed: ' + weatherData.wind.speed +" m/h" + "<br>" + "Humidity: " + weatherData.main.humidity + " %");