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

              
                <link href='https://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'>

<head>
<h1 class='text-center'>Free Code Camp Weather App</h1>
  <h3 class='text-center'>This is your current weather!</h3>
</head>
<body id='body' class='text-center'>
  
  <div id = 'weather' class='container gray-box'>
    <div id = 'icon' class='container weather-box'></div>
    <div id = 'cityName'></div>
    <div id = 'temp'></div>
    <div id = 'scale'></div>
    <div id = 'conditions'></div>
    </div>
  </div>
  <div>
  <input type='text' value='Your city here'></input>
<button id='submit' type='submit' onclick='fahrenheitRequest(images)'>Submit</button>
</div>
  <button id = 'F' type="button" class="btn btn-info btn-lg" onclick='fahrenheitRequest(images)'>F</button>
  <button id = 'C' type="button" class="btn btn-info btn-lg" onclick='celsiusRequest(images())'>C</button>
</body>
              
            
!

CSS

              
                body {
  font-family: 'Raleway', sans-serif;
  background-image: url("http://www.giftgrove.com/photos/CWPortfolioImages/weatherappsunny.jpg");
}
.weather-box {
  background-image: url("http://openweathermap.org/img/w/01d.png") hide;
  width: 45px;
  height: 45px;
}
h1 {
  color: #144673;
  font-size: 40px;
}
h3 {
  color: #3E606F;
}
div {
  font-family: 'Raleway', sans-serif;
  font-size: 20px;
  color: black;
  margin: 30px;
  padding: 10px
}
.gray-box {
  background-color: #D1DBBD;
  opacity: 0.8;
  border-color: #91AA9D;
  border-width: 15px;
  border-style: solid;
  border-radius: 100px;
  min-width: 300px;
  max-width: 500px;
  min-height: 350px;
  max-height: 600px;
}
.icon {
  image-src: url("http://openweathermap.org/img/w/01d.png");
}

@import "lesshat";

#F {
  font-family: 'Raleway', sans-serif;
  background-color: darken(#428bca, 20%) !important;
}
#C {
  font-family: 'Raleway', sans-serif;
  background-color: darken(#428bca, 20%) !important;
}
.true-center {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  height: 106px;
  width: 680px;
}

.btn {
  margin: 15px;
  position: relative;
  border: 0 !important;
  &:focus { outline: 0; }
  &:hover { top: 2px; }
  &:active { top: 6px; }
  cursor: pointer;
  -webkit-font-smoothing: antialiased;
  font-weight: bold !important;
  
  .border-radius(10);
  .transition(all, 50ms, ease);
  .btn(rgb(204, 204, 204), 20%);
  
}

.btn-info {
  .btn(#5bc0de);
}
.btn(@color, @percent: 10%)  {
    border: 0;
    text-shadow: 0px 1px 0px darken(@color, @percent);
    background-color: @color;
    .box-shadow(0px, 6px, 0px, darken(@color, @percent));
    &:hover { 
      border: 0;
      background-color: lighten(@color, 5%) !important;
      .box-shadow(0px, 4px, 0px, darken(@color, @percent));
    }
    &:active { 
      .box-shadow(inset, 0px, 3px, 0px, darken(@color, @percent)); 
    }
}
              
            
!

JS

              
                var images = function () {
  var imgPath = new String(); 
            imgPath = document.getElementById("body").style.backgroundImage;
  var weatherIcon = new String();
            weatherIcon = document.getElementById('icon').style.backgroundImage;
  var description = ['Clear', 'Rain', 'Clouds', 'Snow', 'Mist', 'Thunderstorm', 'Haze', 'Fog'];          
  
            if ($('#conditions').text() == description[0]) { //clear
                document.getElementById("body").style.background =  'lightblue';
              document.getElementById("icon").style.backgroundImage =  'url(http://openweathermap.org/img/w/01d.png)';
            }
              else if ($('#conditions').text() == description[1]) { //rain
                document.getElementById("body").style.backgroundImage =  'url(http://www.giftgrove.com/photos/CWPortfolioImages/weatherapprainy.jpg)';
                document.getElementById("icon").style.backgroundImage =  'url(http://openweathermap.org/img/w/09d.png)';
              }
             else if ($('#conditions').text() == description[2]) { //clouds
                document.getElementById("body").style.backgroundImage =  'url(http://www.giftgrove.com/photos/CWPortfolioImages/weatherappcloudy.jpg)';
               document.getElementById("icon").style.backgroundImage =  'url(http://openweathermap.org/img/w/04d.png)';
            }
            else if ($('#conditions').text() == description[3]) {  //snow
                document.getElementById("body").style.backgroundImage =  'url(http://www.giftgrove.com/photos/CWPortfolioImages/weatherappsnowy2.jpg)'; 
              document.getElementById("icon").style.backgroundImage =  'url(http://openweathermap.org/img/w/13d.png)';
            }
            else if ($('#conditions').text() == description[4]) { //mist
                document.getElementById("body").style.backgroundImage =  'url(http://www.giftgrove.com/photos/CWPortfolioImages/weatherappfog.jpg)'; 
              document.getElementById("icon").style.backgroundImage =  'url(http://openweathermap.org/img/w/50d.png)';
            }
            else if ($('#conditions').text() == description[5]) { //thunderstorm
                document.getElementById("body").style.background =  'gray'; 
              document.getElementById("icon").style.backgroundImage =  'url(http://openweathermap.org/img/w/11d.png)';
            }
            else if ($('#conditions').text() == description[6] || description[7]) { //haze,fog
                document.getElementById("body").style.backgroundImage =  'url(http://www.giftgrove.com/photos/CWPortfolioImages/weatherappfog.jpg)'; 
              document.getElementById("icon").style.backgroundImage =  'url(http://openweathermap.org/img/w/50d.png)';
            }
            else { 
                document.getElementById("body").style.background = 'white'; 
              document.getElementById("icon").style.backgroundImage =  'url(http://openweathermap.org/img/w/01d.png)';
            }
}

function fahrenheitRequest () {
    var city = $('input').val();
  $.get('https://api.openweathermap.org/data/2.5/weather?q='+ city +'&APPID=ec37d7ccc2cded6ba44d72067044eff3&units=imperial', function(data){
    
  $('#cityName').append(data.name).text(data.name);
  $('#temp').append(data.main.temp).text(data.main.temp);
  $('#conditions').append(data.weather[0].main).text(data.weather[0].main);
  $('#scale').text('*F');
    return images();
  }
  );    
}

function celsiusRequest () {
  var city = $('input').val();
  $.get('https://api.openweathermap.org/data/2.5/weather?q='+ city +'&APPID=ec37d7ccc2cded6ba44d72067044eff3&units=metric', function(data){
  
  $('#cityName').append(data.name).text(data.name);
  $('#temp').append(data.main.temp).text(data.main.temp);
  $('#conditions').append(data.weather[0].main).text(data.weather[0].main);
  $('#scale').text('*C');
    return images();
}
  );
}
$(document).ready(function(){
  
  //remove text from input field
  $('input').click(function() {
    $('input').val('');
  });
  //submit button
  $('#submit').click(function(event){
    fahrenheitRequest();
  });
  //enter key
  $('input').keypress(function(event){
    if (event.which == 13){
    $('#submit').click();
    }
  });
  //fahrenheit button
  $('#F').click(function (event){
    fahrenheitRequest();
  });
  //celsius toggle button
  $('#C').click(function(event){
    celsiusRequest();
  });
  
});
              
            
!
999px

Console