Pen Settings



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


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


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.


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.


                <div class="container-fluid all">
  <div id="dialog" class="noselect" title="Welcome!">
  <p>Thank you for using my weather app. <br/><br/> Click on the temperature label to toggle between F&deg and  C&deg.<br/><br/> The application refreshes every 5 minutes for accurate reporting.<br/><br/> <strong>Please allow this application to know your location for accurate weather reporting.</strong><br/><br/> Enjoy!</p>
  <div class="jumbotron">
    <h1 class="text-center">Weather App</h1>
  <div class="row">
    <div class="col-md-12 well" id="city">
      <h2 class="text-center">Weather for</h2>
      <h2 class="text-center data-item" id="city-text"></h2>

      <div class="row">
        <div class="col-md-4" id="weather">
          <img src="" id="weatherImg" class="center-block">
          <h3 class="text-center data-item" id="weather-text"></h3>
        <div class="col-md-4" id="temp">
          <h3 class="text-center">Temperature</h3>
          <h3 class="text-center data-item noselect"><span id="temp-text"></span> <span id="tempMode">F&deg</span></h3>
        <div class="col-md-4" id="wind">
          <h3 class="text-center">Wind Speed</h3>
          <h3 class="text-center data-item" id="wind-text"></h3>
  <div class="footer">
    <div class="container">
      <p class="copyright">Copyright © Brandon Gottschling 2016. All Rights Reserved. Made with the <a href="">openweathermap</a> API.</p>


                body {
  background-color: #404576;

.data-item {
  color: #444;

.well {
  background: #888;
  color: white;

.copyright {
  color: #222;

.noselect {
  -webkit-touch-callout: none; /* iOS Safari */
  -webkit-user-select: none;   /* Chrome/Safari/Opera */
  -khtml-user-select: none;    /* Konqueror */
  -moz-user-select: none;      /* Firefox */
  -ms-user-select: none;       /* IE/Edge */
  user-select: none;           /* non-prefixed version, currently
                                  not supported by any browser */

#tempMode {
  cursor: pointer;


                //necessary global variables for selector caching.
var $tempMode = $("#tempMode");
var $tempText = $("#temp-text");
var $windText = $("#wind-text");
//$(document).ready(function() {
  // this function takes the temperature from the dataHandler and displays the temperature according to the correct temperature unit, and colors the temperature hot or cold.

//function for instruction dialog
  $(function() {
    $( "#dialog" ).dialog();

  function formatTemperature(kelvin) {
    var clicked = false;
    var fahr = ((kelvin * 9 / 5) - 459.67).toFixed(0);
    var cels = (kelvin - 273.15).toFixed(1);
    //initial temperature display

    var firstClick = false;
    //click handler to update the temperature unit of measurement.
    $"click").on("click", function() {
      firstClick = true;
      clicked === false ? clicked = true : clicked = false;
      clicked === true ? $tempMode.html("C&deg") : $tempMode.html("F&deg");
      if (clicked) {
      } else

    if (cels > 24) {
      $("#temp-text").css("color", "red");
    } else if (cels < 18) {
      $("#temp-text").css("color", "blue");
  //handles response data and formats it accordingly since it is an asynchronous response object all data handling and formatting must be done within this function.
  function dataHandler(data) {


    if (data.main.temp && && data.sys) {
      // display location name
      $("#city-text").html( + ", " +;
      // display icon
      if ( {
        var imgURL = "" +[0].icon + ".png";
        $("#weatherImg").attr("src", imgURL);
      // display wind speed
      if (data.wind) {
        var knots = data.wind.speed * 1.9438445;
        $windText.html(knots.toFixed(1) + " Knots");
  //This calls the api with the correct coordinates provided by the getLocation function
  function getWeather(lat, lon) {
    var apiURI = "" + lat + "&lon=" + lon + "&appid=06170c100199dbae1e223cc3dfad960b";

    return $.ajax({
      url: apiURI,
      dataType: "json",
      type: "GET",
      async: "true",

  //Passes the browser's geolocation into the getWeather function once its done the response from the getWeather call will be passed to the data handler for formatting.
  var counter = 0;

  function getLocation() {
    console.log("Update# " + counter++);
    if ("geolocation" in navigator) {
      navigator.geolocation.getCurrentPosition(function(position) {
        getWeather(position.coords.latitude, position.coords.longitude).done(dataHandler);
    } else {
      alert("geolocation not available");
  var updateInterval = setInterval(getLocation(), 300000);