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

              
                <body>
  <div class="container-fluid">
    <div class="row text-center">
      <div class="col-xs-12">
        <h1 id="tittle">Current weather</h1>
      </div>
   </div>
   <div class="row text-center">
     <div class="col-xs-12">
       <p><span id="city"></span><span id="country"></span></p>
     </div>
   </div>
    <div class= "row text-center">
      <div class="col-xs-12">
        <p><span id="address"></span></p>
      </div>
    </div>
    <div class= "row text-center">
      <div class="col-xs-12">
        <p>
          <span id="temp"></span>
          <div id="button" class="btn btn-primary">Change the value of temperature</div>
        </p>
      </div>
    </div>
  <div class= "row text-center">
      <div class="col-xs-12">
        <p><span id="wind-speed"></span></p>
      </div>
    <div class="row text-center">
      <div class="col-xs-12">
        <p id="condition"></p>
      </div>
    </div>
  </div>
  <footer class="navbar navbar-fixed-bottom">
  <div class="text-center">
  Coded by <a href="https://www.freecodecamp.com/losbaltica" target="_blank">Adam Pankowski</a> 2016</div>
  <script src="https://code.jquery.com/jquery-2.2.1.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  </footer>
</body>
              
            
!

CSS

              
                .astext {
    background:none;
    border:none;
    margin:0;
    padding:0;
}


              
            
!

JS

              
                var APIKEY = '74177e52015ca3e411324b938e33898e';

$(document).ready(function () {
  if (window.location.protocol != 'https:') {
    $('#tittle').text("This page does not work over https, please log in via https!");
    $('.logo').css('background-image', "url('https://s-media-cache-ak0.pinimg.com/564x/67/25/e6/6725e6a14fab8817f1e58bab96336842.jpg')");
    $('#button').remove();
  } else {
    getLocation();
    $('#condition').html('<i class="fa fa-spinner fa-pulse fa-3x"></i>');
    $('#wind-speed').html('<i class="fa fa-spinner fa-pulse fa-3x"></i>');
  }
});
function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else {
        alert("Geolocation is not supported by this browser.");
    }
}
function showPosition(position) {
      getWeather(position.coords.latitude, position.coords.longitude);
}
//function getLocation() {
//  $.get('https://ip-api.com/json', function (loc) {
//      $('#city').text(loc.city + ', ' + loc.region + ', ' + //loc.country);
//      getWeather(loc.lat, loc.lon, loc.countryCode);
//    })
//    .fail(function (err) {
//      getWeather();
//    });
//}

function getWeather(lat, lon, countryCode) {
 var weatherAPI = 'https://api.openweathermap.org/data/2.5/weather?lat=' +
    lat + '&lon=' + lon + '&units=imperial' + '&type=accurate' +
    '&APPID=' + APIKEY; // 
  $.get(weatherAPI, function (weatherData) {
      temp = weatherData.main.temp.toFixed(0);
      tempC = ((temp - 32) * (5 / 9)).toFixed(0);
    
      var condition = weatherData.weather[0].description,
        id = weatherData.weather[0].id,
        speed = Number((weatherData.wind.speed * 0.86897624190816).toFixed(1)),
        deg = weatherData.wind.deg,
        windDir,
        iconClass,
        bgIndex,
        backgroundId = [299, 499, 599, 699, 799, 800],
        backgroundIcon = [
          'thunderstorm',
          'sprinkle',
          'rain',
          'snow',
          'night-clear',
          'cloudy',
          'few clouds'
        ],
        backgroundImg = [
        'https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTWvBBma0GbUNflD1_BBeuljgi841lKhPVTTGU3ZZFID86SAwf1',
          'http://www.srh.noaa.gov/jetstream/global/images/dz.jpg',
          'http://www.futurenews.ca/wp-content/uploads/2014/11/rain-wallpaper.jpg',
          'https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcSbK-X0b5JhIhwdT_fOVEvIHLzKP9uWgEIS9IY4GgBWapBWk411',
          'https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSF-QFJYRwcYdHyBhz3oWBnR7ExI6wa_EC4ygcpO_z43tCX7RelvA',
          'https://static.pexels.com/photos/7994/pexels-photo.jpg',
          'https://static.pexels.com/photos/7994/pexels-photo.jpg',
        ];

      backgroundId.push(id);
      bgIndex = backgroundId.sort().indexOf(id);
      $('body').css('background-image', 'url(' + backgroundImg[bgIndex] + ')');
    
  $('body').css('background-size', 'cover');
    
      iconClass = backgroundIcon[bgIndex];

    if (deg) {
      var val = Math.floor((deg / 22.5) + 0.5),
          arr = [
            'N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE',
            'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW',
          ],
          windDir = arr[(val % 16)];
    } else {
      windDir = 'N';
    }

    var fahrenheit = ['US', 'BS', 'BZ', 'KY', 'PL'];
    if (fahrenheit.indexOf(countryCode) > -1) {
      $('#temp').text(temp + '° F');
    } else {
      $('#temp').text(tempC + '° C');
    }

    $('#wind-speed').html(
      '<i class="wi wi-wind wi-from-' + windDir.toLowerCase() + '"></i><br>' +
      windDir + ' ' + speed + ' knots');
    $('#condition').html(
      '<i class="wi wi-' + iconClass + '"></i><br>' + condition);
  })
    .fail(function (err) {
      
    alert('There was an error retrieving your weather data. \n' +
          'Please try again later.');
  });
}

$('#button').click(function () {
  if ($('#temp').text().indexOf('F') > -1) {
    $('#temp').text(tempC + '° C');
  } else {
    $('#temp').text(temp + '° F');
  }

  this.blur();
});

              
            
!
999px

Console