cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-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">
    <h2>Local Weather</h2>
    <div class="well">
      <p id="weather"></p>
      <form action="/select-metric">
          <input type="radio" checked name="farenheit-celcius" id="f"> Farenheit</label>
          <input type="radio" name="farenheit-celcius" id="c"> Celsius</label>
  <p>Copyright © Rafael J. Rodriguez 2015. All Rights Reserved</p>
    <a href="mailto:rafase282@gmail.com">
      <i class="fa fa-envelope fa-fw"></i>
    <a href="https://github.com/Rafase282" target='_blank'>
      <i class="fa fa-github fa-fw"></i>
    <a href="https://www.linkedin.com/in/rafase282" target='_blank'>
      <i class="fa fa-linkedin"></i>
    <a href="https://codepen.io/Rafase282" target='_blank'>
      <i class="fa fa-codepen"></i>
    <a href="https://rafase282.wordpress.com/" target='_blank'>
      <i class="fa fa-wordpress"></i>
    <a href="https://www.freecodecamp.com/rafase282" target='_blank'>
    (<i class="fa fa-fire fa-fw"></i>)
              $font: Verdana, Geneva, sans-serif
$main-color: #663300
  text-align: center
  font-family: $font
  color: $main-color

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

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

  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

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

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

  font-size: 150%

  width: 25%
  height: 25%

              // Setup and get geolocation from the browser.
var units = 'imperial';
var imgs = [
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) {
  } 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;

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';

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
  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];
    case 'C':
      tempArr = [32, 21, 0];
  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

// Handles Unit selection


Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.


Loading ..................