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. 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

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 id="thePage">
  <link href="https://fonts.googleapis.com/css?family=Shrikhand" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Lobster+Two" rel="stylesheet">
  <body>
    <div id="search">
      <form id="getLocation">
        <input id="zipCode" type="text" placeholder="Zip Code(US)"/>
        <input type="button" class="btn" id="newSearch" value="Get Weather"/>
        
      </form>
    <div id="weatherInfo" >
      <p>(Click below to switch between F/C)</p>
      <p id="temperature"><a href="#" id="switchUnits"></a></p>
      
      <p id="conditions"></p>
    </div>
  </body>
</html>
              
            
!

CSS

              
                body{
  background-size: 100%;
}
a, a:link, a:active, a:hover, a:visited{
  text-decoration: none;
  color: white;
}

#weatherInfo{
  height: 100px;
  width: 350px;
  
  position: absolute;
  top:0;
  bottom:0;
  left:0;
  right:0;
  
  margin: auto;
  
  
}
input[type=text] {
   width:110px;
  height: 35px;
  font-size: 16px;
}
input[type=text]:focus {
  width:110px;
  height: 35px;
  font-size: 16px;
}

#temperature{
  text-align: center;
  font-size: 112px;
  font-family: 'Lobster Two';
}
#conditions{
  text-align:center;
  font-size: 32px;
  font-family: 'Lobster Two';
  color: orange;
}

p{
  color: white;
  text-align: center;
}
              
            
!

JS

              
                if(navigator.geolocation){
  navigator.geolocation.getCurrentPosition(function(position){
    var lat = position.coords.latitude;
    var lon = position.coords.longitude;
    var getLatLon = 'http://api.openweathermap.org/data/2.5/weather?lat='+lat+'&lon='+lon+'&units=imperial&APPID=da3b7413dd37ecd406be017e8cbb1d34'
    //call API function
    loadWeather(getLatLon);
 
  })//end of geolocation function
};//end of if(navigator.geoLocation)

$("#newSearch").click(function(){
  var units = "imperial";
  var zip = document.getElementById('zipCode').value;
  var getZip= 'http://api.openweathermap.org/data/2.5/weather?zip='+zip+',us&units='+units+'&APPID=da3b7413dd37ecd406be017e8cbb1d34';
  console.log('API Call will be sent to: ' + getZip);
  loadWeather(getZip, units);
});

function loadWeather(callURL, units){
  var getURL = callURL;
  console.log('API Call sent to: ' + getURL);
  $.getJSON(getURL, function(weather){
    
   if(weather.weather[0].main == 'Clouds'){
        
      document.body.style.backgroundImage = "url('https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQxWZRF3Jk-YhHi8V-3dmryaSx-8JGpn0_UEcxvp-hQwCBvcxwX')";
    } else if(weather.weather[0].main == 'Clear'){ 
      document.body.style.backgroundImage = "url('http://cdn.paper4pc.com/images/clear-sky-wallpaper-1.jpg')";
    }else if(weather.weather[0].main == 'Rain'){
      document.body.style.backgroundImage = "url('https://i.ytimg.com/vi/J5OSRpRyl6g/maxresdefault.jpg')"
    }else if(weather.weather[0].main == 'Drizzle'){
      document.body.style.backgroundImage = "url('https://i.ytimg.com/vi/LbAigABOm_E/maxresdefault.jpg')"
    }else if(weather.weather[0].main == 'Thunderstorms'){
      document.body.style.backgroundImage = "url('http://www.goodwp.com/images/201501/goodwp.com_32159.jpg')";
    }else if(weather.weather[0].main == 'Extreme'){
      document.body.style.backgroundImage = "url('https://www.mos.org/sites/dev-elvis.mos.org/files/images/main/uploads/slides/imax_extreme-weather_tornado.jpg')";
    }else{
      document.body.style.backgroundImage = "url('http://awesomeocean.com/wp-content/uploads/2014/09/Flat-Ocean.jpeg')";
    }//end of weather type/background if statement
   

 
    document.getElementById("switchUnits").innerHTML =      Math.round(weather.main.temp) +'° F';
document.getElementById("conditions").innerHTML = 
weather.weather[0].main;
    
  })//end of getJSON
}
$("#switchUnits").click(function(){
  
  var text = $('#switchUnits').text();
  
  if(text.includes('F')){
   var temp = text.replace(/[^0-9]/g, "");
    
    temp = Math.round(((temp-32)*5) / 9);
    
    $('#switchUnits').empty();
    document.getElementById("switchUnits").innerHTML =      temp +'° C';
document.getElementById("conditions").innerHTML = 
weather.weather[0].main;
    
  }else{
    var temp = text.replace(/[^0-9]/g, "");
    
    temp = Math.round((temp * 1.8)+32);
    
    $('#switchUnits').empty();
    document.getElementById("switchUnits").innerHTML =      temp +'° F';
document.getElementById("conditions").innerHTML = 
weather.weather[0].main;
    //if text doesn't contain F then it is already metric and needs to be calculated for imperial units here
  }
});
              
            
!
999px

Console