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.

            
              <link href='https://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script> 
<div class="back">

<h1 class="head center groove">A WEATHER APP</h1>
  
    <div id="city">
    <p class="center">Click the button to get your local weather.</p></div>
  <div  id="temp"></div>
  

<div class="center-div">
  
  <button class="buttonone"id="getWeather" >Get Current Weather</button>
</div>
</div>

   


            
          
!
            
              h1{border-style:groove;
display:block;
border-width:2px;
background-color:DodgerBlue;
border-color:white;}
.back{background-color:Lightseagreen;
  padding:10px;
}
.head{color:white;
  font-family:Raleway, Arial;
  font-size:60px;
  
  
}

.center{text-align:center;
font-family:Raleway
  ;
}

#city {
  text-align: center;
  font-size: 30px;
font-family:Raleway;}
  #temp {
    text-align:left;
    font-size:30px;
    font-family:Raleway;
}

.buttonone {
	margin: 30px auto;
	padding: 20px 30px;
  font-family:Arial;
  font-size:20px;
  color:Azure;
  background-color:Lawngreen;
  border-color:#00FA9A;
  border-width:5px;
  border-radius:30px;
  ;
  
}

.myclass{font-family:Raleway;
}
.center-div { text-align: center; width: 500px; margin: 20px auto; }
.button{
  margin:5px;
  padding:5px;
}
            
          
!
            
              $(document).ready(function() {
$( "#getWeather" ).click(function() {
	tryToGetLocation();
});

var APP_ID = "3abdc25e06a9753f60cafd4efa793ba3";
var API_DATA={};
  var Celsius_Result=0;
  
  
   $('body').on('click', '#getTemp', function() {
    convertFtoC();
  });
  
  
  $('body').on('click', '#getMoreTemp', function() {
    convertCtoF();
  });

  
function success(position) {
	console.log('position',position);
	var latitude = position.coords.latitude;
	var longitude = position.coords.longitude;
	getData( latitude, longitude );
};

function error(error) {
	console.log('error',error);
	alert(error.message);
};

var options = {
	maximumAge: 50000,
	enableHighAccuracy: true
}

var tryToGetLocation = function() {
	if ( navigator.geolocation ) {
		navigator.geolocation.getCurrentPosition( success, error, options);
	} else {
		alert("Geolocation is disabled, please enable it");
	}
};


function getData( latitude, longitude ) {
	$.getJSON("https://crossorigin.me/http://api.openweathermap.org/data/2.5/weather?lat=" + latitude + "&lon="+ longitude + "&APPID=" + APP_ID + "&callback=", callbackFuncWithData);
}

function callbackFuncWithData(data) {
  API_DATA=data;
	console.log("data",data);
	$("#city").html("<span class='myclass'>City:"  + data.name+"</span>"
  );
  $("#temp").html("Temperature: "+data.main.temp);
  $("#temp").append('<button class="button" id="getTemp"> &deg;F</button>');
  
	$("#weather").html("<span class='myclass'>Weather: " + data.main.weather +"</span");
}
  //Update Weather animation based on the returned weather description
   
var convertFtoC=function(){
  var Celsius=(API_DATA.main.temp-32)/(9/5);Celsius_Result=Celsius.toFixed(2);
  $("#temp").html("Temperature: "+Celsius.toFixed(2)+'<button class="button" id="getMoreTemp"> &deg;C</button>')};


var convertCtoF=function(){
  var Fahrenheit=(Celsius_Result*(9/5))+32;
  $("#temp").html("Temperature: "+Fahrenheit.toFixed(2)+'<button class="button" id="getTemp"> &deg;F</button>');}




});


            
          
!
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