Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <head>
    <meta charset="utf-8">  
    <script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>
    <script src="https://code.jquery.com/jquery-3.3.1.js"
            integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
            crossorigin="anonymous"></script>
</head>
<body onload="updateClock(); setInterval('updateClock()', 1000)">
  <div id="weather">
    <div id="location">
      <h1><span id="loc"></span></h1>
        <p><span id="day"></span><span id="clock">&nbsp;</span></p>
    </div>
    <div id="temps" class="boxy boxed">
      <p><span id="temp"></span><span id="tempUnits"></span></p>
      <p><button id="switchDegrees" onclick="switchUnits()">convert &#176;</button></p></div>
    <div id="conditions" class="boxy">  
      <p><span id="icon"></span></p><p><span id="skies"></span></p>
    </div>
      <div class="boxy boxed"><p><span id="humidity"></span></p>
        <p>humidity</p>
    </div>
    
  </div>

  <footer>created by <a href="https://jmf.codes">jmf.codes</a> with help from <a href="https://www.freecodecamp.org/jennifermf">Free Code Camp</a>.</footer>
</body>
              
            
!

CSS

              
                body {
  font-family: sans-serif, monospace;
  font-size: 1.5em;
  font-weight: bold;
  text-align: center;
  background-repeat: no-repeat;
  background-size: cover;
}
h1, p, footer {
  /* Width and color values */
  -webkit-text-stroke: 0.2px white; 
}
h1 {
  font-size: 3em;
}
#weather {
  width: 75%;
  margin: 0 auto;  
}
#temp:after {
  content: "\00b0";
}
#humidity:after {
  content: "%";
}
#clock {
 font-family: monospace;
 font-size: 1.5em;
 background: rgba(0,0,0,0.3);
 padding: 1.5%;
}
.boxy {
  display: inline-block;
  width: 25%;
}
.boxed {
  background: rgba(0,0,0,0.3);
}
#conditions {
  margin-top: 5%;
  padding: 1%;
}
footer {
  font-size: 0.7em;
  margin-top: 100px;
  bottom: 0;
  text-align: center;
}
              
            
!

JS

              
                /* tasks: 
1. see the weather in my current location.
2. see a different icon or background image depending on the weather.
3. button toggle between Fahrenheit and Celsius. */ 

function switchUnits() {
  var units = document.getElementById('tempUnits').textContent;
  var currentTemp = document.getElementById('temp').textContent;
    // change temp from C to F
    if (units === "C") {
      // convert C to F
      var newtemp = Math.floor(currentTemp * 9/5 + 32);
      units = "F";
      document.getElementById('temp').innerHTML = newtemp;
      document.getElementById('tempUnits').innerHTML = units;
    }
    else {
      // convert F to C
      var newtemp = Math.floor((currentTemp - 32) * 5 / 9); 
      units = "C";
      document.getElementById('temp').innerHTML = newtemp;
      document.getElementById('tempUnits').innerHTML = units;
    };
  };
$(document).ready(function() {
  var currentTime = new Date();
  var currentHours = currentTime.getHours();
  var currentMinutes = currentTime.getMinutes();
  currentMinutes = (currentMinutes < 10 ? "0" : "") + currentMinutes;
  var timeOfDay = (currentHours < 12) ? "AM" : "PM";
  currentHours = (currentHours > 12) ? currentHours - 12 : currentHours;
  currentHours = (currentHours == 0) ? 12 : currentHours;
  var currentTimeString = currentHours + ":" + currentMinutes + " " + timeOfDay;
  document.getElementById("clock").firstChild.nodeValue = currentTimeString;
  
  var tempUnits = document.getElementById("tempUnits");
  var currentTemp = document.getElementById('#temp');
  
  if (navigator.geolocation) { 
  //Set geo location lat and long 
  navigator.geolocation.getCurrentPosition(function(position, html5Error) {
    geo_loc = processGeolocationResult(position);
    LoadWeather();
    SetBackground();
  });
  //Get geo location result
  function processGeolocationResult(position) {
    html5Lat = position.coords.latitude; //Get latitude
    html5Lon = position.coords.longitude; //Get longitude
    return [(html5Lat).toFixed(8), (html5Lon).toFixed(8)];
  }; }
  else {
    console.log("Oops! We need geolocation data to give you a weather report.");
  }  
  // now let's plug that in and get the weather: 
  function LoadWeather() {
    $.ajax({
      url: 'https://fcc-weather-api.glitch.me/api/current',
      type: 'GET',
      dataType: 'json',
      data: { 'lat': geo_loc[0], 'lon': geo_loc[1], }, 
      success: function(response) {
        $('#loc').text(response.name);
        $('#temp').text(Math.floor(response.main.temp));
        $('#tempUnits').text("C"); 
        $('#skies').text(response.weather[0].description);     
        $('#humidity').text(response.main.humidity);      
        $('#icon').html('<img src="' + response.weather[0].icon + '" />');
        $('#everything').html(BgGenerator());
      },
    }); 
 
  };
  
function updateClock() {
  var currentTime = new Date();
  var currentHours = currentTime.getHours();
  var currentMinutes = currentTime.getMinutes();
  currentMinutes = (currentMinutes < 10 ? "0" : "") + currentMinutes;
  // Choose either "AM" or "PM" as appropriate
  var timeOfDay = (currentHours < 12) ? "AM" : "PM";
  // Convert the hours component to 12-hour format if needed
  currentHours = (currentHours > 12) ? currentHours - 12 : currentHours;
  // Convert an hours component of "0" to "12"
  currentHours = (currentHours == 0) ? 12 : currentHours;
  // Compose the string for display
  var currentTimeString = currentHours + ":" + currentMinutes + " " + timeOfDay;
  // Update the time display
  document.getElementById("clock").firstChild.nodeValue = currentTimeString;
}; 
 
function BgGenerator() {
  var skies = document.getElementById('skies').innerHTML;
  switch (skies) {
    case 'drizzle':
      document.body.style.backgroundImage = 'url(http://oi44.tinypic.com/207146a.jpg)';
      break;
    case 'clouds':
      document.body.style.backgroundImage = 'url(http://oi44.tinypic.com/2gvu55g.jpg)';
      break;
    case 'broken clouds':
      document.body.style.backgroundImage = 'url(http://oi44.tinypic.com/2gvu55g.jpg)';
      break;
    case 'overcast clouds':
      document.body.style.backgroundImage = 'url(http://oi44.tinypic.com/2gvu55g.jpg)';
      break;
    case 'rain':
      document.body.style.backgroundImage = 'url(http://oi44.tinypic.com/207146a.jpg)';
      break;
    case 'snow':
      document.body.style.backgroundImage = 'url(http://oi39.tinypic.com/5fj8jq.jpg)';
      break;
    case 'clear sky':
      document.body.style.backgroundImage = 'url(http://oi42.tinypic.com/i3gdtu.jpg)';
      break;
    case 'thunderstom':
      document.body.style.backgroundImage = 'url(http://oi43.tinypic.com/2u7anoi.jpg)';
      break;
    default:
      document.body.style.backgroundImage = 'url(http://oi40.tinypic.com/jqnrza.jpg)';
  }
}
  
});


 

/* 
bibliography: 

Free Code Camp project requirements:
https://www.freecodecamp.org/challenges/show-the-local-weather

about geolocation:
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation

thanks to cuelogic for the lat/long code:
http://www.cuelogic.com/blog/how-to-get-user-latitude-longitude-current-address-using-html5/ 

ajax:
https://www.w3schools.com/jquery/ajax_ajax.asp

clock:
https://www.elated.com/articles/creating-a-javascript-clock/
*/
              
            
!
999px

Console