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.

            
              <div class="row centered-form center-block">
    <div class="container col-md-8 col-md-offset-2">

<div class="container-fluid myBackground">
<h1 class="text-center">Weather Generator</h1>

<div class="row">
<div class="col-xs-4">
<h1> You Are Here: </h1><span id="location"></span>
  </div>
<div class="col-xs-4">
  <h1> Temperature: </h1><div><span id="temperature"></span>
  <span id="cel"></span>
  <button id="degrees">Switch Between Fahrenheit and Celcius</button>
  </div>
  </div>
<div class="col-xs-4">
<h1>Details: </h1>  <span id="details"></span>
  <span id="icon"><img src="http://openweathermap.org/img/w/10d.png"></span>
  </div>
  </div>
  
  </div><!-- closes row -->
<div class="footer text-center myBackground"> <em>Don't forget your umbrella...-Mike</em>
<p>No data? Try loading using https instead of http.
</div>
      
  </div>
</div>
            
          
!
            
              body{
 background-image: url("http://u01.appmifile.com/images/2016/06/19/d2f383a2-2e76-44b8-acab-283771f7be80.jpg");
  background-color: blue;
  background-repeat: no-repeat;
  background-position: center;
  background-attachment: fixed;
  background-size: cover;
}
span {
  color: red;
  font-size: 28px;
}
h1 {
  font-family: Impact;
  color: brown;  
  text-align: center;
}
button {
  font-size: 14px;
}
#cel {
  display: none;
}
#temperature {
  display: inline;
}
.myBackground {
  background-color: rgba(255,255,255, 0.5);
  color: inherit;
}

            
          
!
            
              var APPID = "5f208d5a783a7f02e9c53400957f8e3a",
fah = '',
celc = '',
current = 1;
//Future updates: 
//Make it responsive for mobile (for some reason it isn't working)
//Design updates to make it more like a widget
//Cooler weather icons, theirs are kind of lame.
//Kelvin option with a nuclear explosion background

$("#degrees").click(function (){
  if (current == 1){
  $("#temperature").css('display', 'none');
 $("#cel").css('display', 'inline');
    current = 0;
      }
  else if (current == 0){
$("#temperature").css('display', 'inline');
 $("#cel").css('display', 'none');
    current = 1;
  };
});

window.onload = function () {
  /* NEW */
    if(navigator.geolocation){
	var showPosition = function(position){
	    updateByGeo(position.coords.latitude, position.coords.longitude);
	}
	navigator.geolocation.getCurrentPosition(showPosition);
    } else {
	var zip = window.prompt("Could not discover your location. What is your zip code?");
	updateByZip(zip);
}

/* NEW */

function updateByGeo(lat, lon){
    var url = "https://api.openweathermap.org/data/2.5/weather?" +
	"lat=" + lat +
	"&lon=" + lon +
	"&APPID=" + APPID;
    sendRequest(url);    
}

function updateByZip(zip){
    var url = "https://crossorigin.me/http://api.openweathermap.org/data/2.5/weather?" +
	"zip=" + zip +
	"&APPID=" + APPID;
    sendRequest(url);
}

function sendRequest(url){
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            var data = JSON.parse(xmlhttp.responseText);
	    var weather = {};
	    weather.location = data.name;
	    weather.temp = K2F(data.main.temp);	
      weather.celcius = K2C(data.main.temp);
       weather.main = data.weather[0].description;
      weather.icon = data.weather[0].icon;	    update(weather);

	}
    };

    xmlhttp.open("GET", url, true);
    xmlhttp.send();    
}
  function update(weather) {
    $("img").attr("src", "https://openweathermap.org/img/w/" + weather.icon + ".png");
  fah = weather.temp;
  $("#location").html(weather.location + "<br />");
$("#temperature").html(fah + "&deg F <br />");
  celc = weather.celcius;
  $("#cel").html(celc + "&deg C <br />");
 $("#details").html(weather.main + "<br />");
}
//Switch to Fahrenheit
function K2F(k){
    return Math.round(k*(9/5)-459.67);
};
//Switch to Celcius
function K2C(k){
    return Math.round(k - 273.15);
};
};


            
          
!
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