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>
<div class="container flow-text">
  <div class="row">
    <div class="col s12 m6 offset-m3">
      <div class="card blue-grey lighten-1">
        <div class="card-content blue-grey-text text-lighten-5 center-align">
          <div id="latLong">LOCATION: </div>
          <div id="currentWeather">CONDITIONS: </div>
          <div id="icon"><canvas id="icon1" width="200" height="200"></canvas></div>
          <div id="temperature"><span id="tempText"></span><span id="tempUnits">F</span></div>
          <div>
            <a class="waves-effect waves-light btn blue-grey lighten-4 blue-grey-text text-darken-2" id="FCButton">Switch C/F</a>
          </div>
          <div class="divider"></div>
          <div class="center-align">
            <a class="waves-effect waves-light btn blue-grey lighten-4 blue-grey-text text-darken-2 activator">credits</a>
          </div>
        </div>
        <div class="card-reveal blue-grey darken-3 blue-grey-text text-lighten-5">
          <span class="card-title">CREDITS<i class="material-icons right">close</i></span></span>
          <p>By Andy Bonner, 2016</p>
          <p>for <a href="https://www.freecodecamp.com/challenges/show-the-local-weather">FreeCodeCamp</a></p>
          <p>Weather data is provided by the <a href="http://forecast.io/">Forecast.io</a> API, and the icons by their <a href="https://darkskyapp.github.io/skycons/">"Skycons."</a> Layout and DOM manipulation use <a href="http://materializecss.com/">Materialize</a>.
        </div>
      </div>
    </div>
  </div>
</div>
</body>
              
            
!

CSS

              
                body {
  background-attachment: fixed;
  background-repeat: no-repeat;
  background: blue;
  /* For browsers that do not support gradients */
  background: -webkit-linear-gradient(#78909c, #263238) fixed;
  /* For Safari 5.1 to 6.0 */
  background: -o-linear-gradient(#78909c, #263238) fixed;
  /* For Opera 11.1 to 12.0 */
  background: -moz-linear-gradient(#78909c, #263238) fixed;
  /* For Firefox 3.6 to 15 */
  background: linear-gradient(#78909c, #263238) fixed;
  /* Standard syntax */
}

.container {
  font-weight: bold;
}

.btn {
  margin: 4%;
}
              
            
!

JS

              
                function getLocalWeather() {
  var lat, long;
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(success, error, geoOptions);
  } else {
    alert("Geolocation services are not supported by your web browser.");
  }

  function success(position) {
    lat = position.coords.latitude.toFixed(5);
    long = position.coords.longitude.toFixed(5);
    getWeather(lat, long);
    $("#latLong").append(lat + "°, " + long + "°");
  }

  function error(error) {
    alert("This app only works over a secure connection. Please add 'https://' to the beginning of the URL (i.e. 'https://codepen.io/AbdiViklas/pen/NrRxqx'). Error code and message: " + error.code + ": " + error.message);
  }

  var geoOptions = {
    enableHighAccuracy: true,
    maximumAge: 30000,
    timeout: 27000
  };
}

function getWeather(latitude, longitude) {
  $.getJSON("https://api.forecast.io/forecast/25dafa45c7e7aacbe25bdfd1dfbdc89e/" + latitude + "," + longitude + "?callback=?", function(data) {
    var conditions = data.currently.summary;
    var tempF = data.currently.temperature;
    var tempC = (tempF - 32) / 1.8
    var icon = data.currently.icon;
    $("#currentWeather").append(conditions);
    var skycons = new Skycons({"color": "#f3e5f5"}); //this line generates the set of Skycons, and also changes the default color to a hint of purple
    skycons.set("icon1", icon); //this first points to the <canvas> element with ID "icon1," and the sets the var icon above to it
    skycons.play(); //and the animation starts!
    $("#tempText").text("TEMP: " + Math.round(tempF) + "°");
    $("#tempUnits").text("F");
    $("#FCButton").click(function() {
      if ($("#tempUnits").text() === "F") {
        $("#tempText").text("TEMP: " + Math.round(tempC) + "°");
        $("#tempUnits").text("C");
      } else {
        $("#tempText").text("TEMP: " + Math.round(tempF) + "°");
        $("#tempUnits").text("F");
      }
});
  })
}

$(document).ready(getLocalWeather());
              
            
!
999px

Console