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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <!--Header/Title-->
<div id='titleDiv'>
  <h1 id='title'>Free C<span id ='weatherIcon' class="fa fa-sun-o"></span>de <br> Camp Weather App<h1>
</div>
    
<!--Weather-->
<div id='outputDiv'>
  <p id='location'>Location</p>
  
<div id='weatherDiv'>  
  
  <p id='weather'></p>
  <button type='button' class='btn btn-link'id='degreeIcon'>&#8457;</button>
  <p id='summary'>Currently</p>
  
    <p>
  <span id ='dynamicIcon' class="fa fa-umbrella"></span></p>
    
</div> 
</div>
              
            
!

CSS

              
                body {
  background-color: black;
}

#title {
  color: white;
  text-align: center;
  font-size: 5em;
}

#weatherDiv {
  text-align: center;
  margin-right: -.5em;
}

#weather {
  color: white;
  text-align: center;
  display: inline;
  font-size: 1.5em;
  margin-right: -.5em;
}

#summary {
  color: white;
  text-align: center;
  font-size: 1em;
  margin-left: -.5em;
}

#degreeIcon {
  display: inline;
  margin-top: -.5em;
}

#location {
  color: white;
  text-align: center;
}

#dynamicIcon {
  text-align: center;
  color: white;
  font-size: 5em;
  margin-left: -.1em;
}


              
            
!

JS

              
                $(document).ready(function() {
  //Create variable to store toggle value
  var toggle = 0;
  //Create global temperature variable;
  var temperature;
  //Create variables to store lattitude and longitude
  var lat;
  var lng;
  //Variable to store the API URL
  var api =
    "https://api.darksky.net/forecast/bf16f40a088d7397565ec923c6224b19/";
  //Variables to store the Google API URL and API key
  var googleAPI = "https://maps.googleapis.com/maps/api/geocode/json?latlng=";
  var googleKey = "AIzaSyBtRdxPYuhsbgguygE4fuYW5pFxIibDD6I";

  //Get the user's current location
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      (lat = position.coords.latitude), (lng = position.coords.longitude);
      getTheWeather(lat, lng);
    });
  }

  //Funtion to display the weather. Is a function becuase lat lng calls take a bit of time so it needs to be nested in the previous location call
  function getTheWeather(lat, lng) {
    //Create full Dark Skey API URL String
    var urlString = api + lat + "," + lng;
    //Create full Google Maps API URL String
    var googleString = googleAPI + lat + "," + lng + "&key=" + googleKey;
    //Get City by reverse geolocation
    $.getJSON(googleString, function(results) {
      var city = JSON.stringify(
        results.results[0].address_components[3].long_name
      );
      var state = JSON.stringify(
        results.results[0].address_components[5].short_name
      );
      city = city.replace(/['"]+/g, "");
      state = state.replace(/['"]+/g, "");
      var cityState = city + ", " + state;
      $("#location").html(cityState);
    });

    //Call the Dark Sky API
    $.getJSON(urlString, function(json) {
      //Store the current temperature in the temperature variable
      temperature = JSON.stringify(json.currently.temperature);
      //Replaces weather text with the current temperature
      $("#weather").html(Math.round(temperature));

      //Store current weather summary in currentWeather variable
      var currentWeather = JSON.stringify(json.currently.summary);
      var summary = currentWeather;
      summary = summary.replace(/['"]+/g, "");
      $("#summary").html(summary);
      //Change the icon based on the Current Weather

      if (currentWeather.indexOf("Clear") >= 0) {
        document.getElementById("dynamicIcon").className = "fa";
        document.getElementById("dynamicIcon").className += " fa-sun-o";
      }
      if (currentWeather.indexOf("Rain") >= 0) {
        document.getElementById("dynamicIcon").className = "fa";
        document.getElementById("dynamicIcon").className += " fa-umbrella";
      }
      if (currentWeather.indexOf("Drizzle") >= 0) {
        document.getElementById("dynamicIcon").className = "fa";
        document.getElementById("dynamicIcon").className += " fa-tint";
      }
      if (currentWeather.indexOf("Clouds") >= 0) {
        document.getElementById("dynamicIcon").className = "fa";
        document.getElementById("dynamicIcon").className += " fa-cloud";
      }
      if (currentWeather.indexOf("Snow") >= 0) {
        document.getElementById("dynamicIcon").className = "fa";
        document.getElementById("dynamicIcon").className += " fa-snowflake-o";
      }
      if (currentWeather.indexOf("Thunderstorm") >= 0) {
        document.getElementById("dynamicIcon").className = "fa";
        document.getElementById("dynamicIcon").className += " fa-bolt";
      }

      //Broken switch statement
      /*
      switch (currentWeather) {
        case "'Clear'":
          document.getElementById("dynamicIcon").className = "fa";
          document.getElementById("dynamicIcon").className += " fa-sun-o";
          break;

        case "Rain":
          document.getElementById("dynamicIcon").className = "fa";
          document.getElementById("dynamicIcon").className += " fa-umbrella";
          break;

        default:
          $("#jsonPlaceHolder").html(currentWeather);      
      }
      */
    });
  }

  //Toggle farenheight and celcius icons
  $("#degreeIcon").click(function() {
    if (toggle == 0) {
      //Set icon to Celcius
      $("#degreeIcon").html("&#8451;");
      toggle = 1;
      //Convert temperature to Celcius
      temperature = (temperature - 32) * 5 / 9;
      $("#weather").html(Math.round(temperature));
    } else if (toggle == 1) {
      //Set icon to Farenheight
      $("#degreeIcon").html("&#8457;");
      toggle = 0;
      //Convert temperature back to farenheight
      temperature = temperature * 9 / 5 + 32;
      $("#weather").html(Math.round(temperature));
    }
  });
});

              
            
!
999px

Console