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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <section class="container-fluid">
    <h1>FreeCodeCamp</h1>
    <h2>Local Weather</h2>
    <div class="well">
      <p id="weather"></p>
      <form action="/select-metric">
        <label>
          <input type="radio" checked name="farenheit-celcius" id="f"> Farenheit</label>
        <label>
          <input type="radio" name="farenheit-celcius" id="c"> Celsius</label>
      </form>
    </div>
  </section>
<footer>
  <p>Copyright © Rafael J. Rodriguez 2015. All Rights Reserved</p>
  <p>
    <a href="mailto:rafase282@gmail.com">
      <i class="fa fa-envelope fa-fw"></i>
    </a>
    <a href="https://github.com/Rafase282" target='_blank'>
      <i class="fa fa-github fa-fw"></i>
    </a>
    <a href="https://www.linkedin.com/in/rafase282" target='_blank'>
      <i class="fa fa-linkedin"></i>
    </a>
    <a href="https://codepen.io/Rafase282" target='_blank'>
      <i class="fa fa-codepen"></i>
    </a>
    <a href="https://rafase282.wordpress.com/" target='_blank'>
      <i class="fa fa-wordpress"></i>
    </a>
    <a href="https://www.freecodecamp.com/rafase282" target='_blank'>
    (<i class="fa fa-fire fa-fw"></i>)
  </a></p>
</footer>
            
          
!
            
              $font: Verdana, Geneva, sans-serif
$main-color: #663300
h2 
  text-align: center
  font-family: $font
  color: $main-color

h1 
  font-size: 52px
  text-align: center
  font-family: $font
  color: $main-color

section 
  min-height: 90vh
  padding-top: 10px
  padding-bottom: 10px
  color: #fff
  bottom: 10px

footer 
  background-color: black
  color: gray
  line-height: 20px
  padding-top: 10px
  padding-bottom: 6px
  position: fixed
  text-align: center
  font-family: $font
  width: 100%
  bottom: 0

.well 
  text-align: center
  color: black
  margin-top: 50px
  margin-left: 30%
  margin-right: 30%
  background-color: rgba(255,255,255,0.75)

body 
  -webkit-background-size: cover
  -moz-background-size: cover
  -o-background-size: cover
  background-size: cover
  background-size: 100% 100%

p
  font-size: 150%

.icon 
  width: 25%
  height: 25%

            
          
!
            
              // Setup and get geolocation from the browser.
var units = 'imperial';
var imgs = [
  'url("https://i.imgur.com/eI5KLUW.jpg")',
  'url("https://i.imgur.com/rG0P1ro.jpg")',
  'url("https://i.imgur.com/voCuONs.jpg")',
  'url("https://i.imgur.com/5tFHSKa.jpg")',
];
var Coordinates = function(lat, lon) {
  this.latitude = lat;
  this.longitude = lon;
};

var coord = new Coordinates(0, 0);

function getLocation() {
  // Request location consent from user
  var display = document.getElementById('weather');
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else {
    display.innerHTML = 'Geolocation is not supported by this browser.';
  }
};

function showPosition(position) {
  // Stores requested into on global variables.
  coord.latitude = position.coords.latitude;
  coord.longitude = position.coords.longitude;
  callWeatherAPI();
};

function getURL(lat, lon, units) {
  // Generates custom URL, the appid is unique for this app.
  var appid = '16c3de9108ed16c9179c1c51008b687e';
  return 'http://api.openweathermap.org/data/2.5/weather?lat=' + lat +
    '&lon=' +
    lon + '&units=' + units + '&appid=' + appid;
};

function Unit() {
  // Selects the right unit for the weather and calls the API
  $('#f').is(':checked') ? units = 'imperial' : units = 'metric';
  callWeatherAPI();
};

function getWeather(data) {
  // Gets the weather after the API call.
  var temp = data.main.temp;
  var tempUnit = units === 'metric' ? 'C' : 'F';
  var windUnit = units === 'metric' ? ' meters/sec' : ' miles/hour';
  var description = data.weather[0].description;
  var code = data.weather[0].icon;
  var wspeed = data.wind.speed;
  var city = data.name;

  // Create custom HTML to display all the information gathered.
  var html = '<img src="https://openweathermap.org/img/w/' + code +
    '.png" alt="Weather Icon" class="icon">' + '<p> ' + Math.round(temp) + ' ' + tempUnit +
    ', ' + description + '<br> Wind Speed: ' + wspeed + windUnit + '</p><p>' +
    city + '</p>';

  // Displays the custom HTML
  $('#weather').html(html);
  var tempArr = prepBackground(tempUnit);
  setBackground(temp, tempArr);

};

function setBackground(temp, tempArr) {
  // Select custom backgroudn image according to temperature range.
  if (temp >= tempArr[0]) {
    $('body').css('background-image', imgs[0]);
  } else if (temp < tempArr[0] && temp >= tempArr[1]) {
    $('body').css('background-image', imgs[1]);
  } else if (temp < tempArr[1] && temp >= tempArr[2]) {
    $('body').css('background-image', imgs[2]);
  } else if (temp < tempArr[2]) {
    $('body').css('background-image', imgs[3]);
  }
};

function prepBackground(tempUnit) {
  // Checks what kind style of temperature was used for dynamic background image.
  var tempArr;
  switch (tempUnit) {
    case 'F':
      tempArr = [90, 70, 32];
      break;
    case 'C':
      tempArr = [32, 21, 0];
      break;
  }
  return tempArr;
};

function callWeatherAPI() {
  // Calls the API to get the wheather information.
  var url = getURL(coord.latitude, coord.longitude, units);
  $.getJSON(url, getWeather);
};

function start() {
  // Function to call all functions and make the app tic
  getLocation();
  callWeatherAPI();
};

// Handles Unit selection
$('input[type=radio][name=farenheit-celcius]').change(Unit);
$(document).ready(getLocation);

            
          
!
999px
Loading ..................

Console