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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 class="main">

  <h1 class="main-header color" id="main-header">Local Weather</h1>

  <div class="date color" id="date"></div> <!-- div for the date and time -->

  <div class="location color" id="location"></div> <!-- div for geo-location -->

  <div class="temp color" id="temp"></div> <!-- div for temperatures -->

  <button type="button" class="color" id="far">F&deg</button>

  <button type="button" class="color" id="cel">C&deg</button>

</body>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}
body {
  background: url() no-repeat center center fixed;
  background-size: cover;
  text-align: center;
}
div,
h1 {
  font-size: 5em;
  color: wheat;
}
h1 {
  letter-spacing: 10px;
  font-weight: lighter;
  font-family: Optima, serif;
}
button {
  height: 75px;
  width: 100px;
  border: 5px solid wheat;
  border-radius: 10%;
  font-size: 2.5em;
  color: wheat;
  background-color: transparent;
  outline: none;
}
button:hover {
  background-color: rgba(0,0,0,0.5);
}
              
            
!

JS

              
                const userLocation = document.getElementById('location');
const localTemp = document.getElementById('temp');

// Main Function

function geoFindMe() {

  // GeoLocation API
  $.getJSON('https://freegeoip.net/json/').done(function (place) {

    $('#location').html(place.city + ', ' + place.region_code);

    // Weather API
    $.getJSON('https://api.openweathermap.org/data/2.5/weather?lat=' + place.latitude + '&lon=' + place.longitude +
    '&units=imperial&appid=4a57261bd57c7c76003822133b03c5b8', function (data) {

        localTemp.innerHTML = Math.round(data.main.temp) + 'F';

        // Event Listener for Celcius button
        $('#cel').click(function () {
          let fTemp = data.main.temp;
          const fToCel = (fTemp - 32) * 5 / 9;
          localTemp.innerHTML = Math.round(fToCel) + 'C';
        });
        // Event Listener for Farenhiet button
        $('#far').click(function () {
          localTemp.innerHTML = Math.round(data.main.temp) + 'F';
        });

        // Conditionals to change background pictures
        if (data.cod < 300) {
          $('.main').css('background-image', 'url(images/thunderstorm.jpeg)');
          $('.color').css('color', 'wheat');
          $('.color').css('border-color', 'wheat');
        }else if (data.cod < 600) {
          $('.main').css('background-image', 'url(images/rain.jpeg)');
          $('.color').css('color', 'white');
          $('.color').css('border-color', 'white');
        }else if (data.cod < 700) {
          $('.main').css('background-image', 'url(images/snow.jpeg)');
          $('.color').css('color', 'black');
          $('.color').css('border-color', 'black');
        }else if (data.cod < 800) {
          $('.main').css('background-image', 'url(images/fog.jpg)');
          $('.color').css('color', 'black');
          $('.color').css('border-color', 'black');
        }else if (data.cod > 800) {
          $('.main').css('background-image', 'url(images/cloudy.jpeg)');
          $('.color').css('color', 'black');
          $('.color').css('border-color', 'black');
        }else if (data.cod == 800) {
          $('.main').css('background-image', 'url(images/sunny.jpg)');
          $('.color').css('color', 'black');
          $('.color').css('border-color', 'black');
        }
      });
  });
}

// Sets the Date

function date() {
  var currentDate = document.getElementById('date');
  var d = new Date();
  var str = (d.getMonth() + 1) + '/' + d.getDate() + '/' + d.getFullYear();
  currentDate.innerHTML = str;
}

geoFindMe();
date();

              
            
!
999px

Console