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. 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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              

<body>

    <div class="page-container">

      <div class="wrapper">

          <div class="location-area">
            <h2>???, ???</h2>
            <h3>??:??</h3>
          </div>
          <div class="weather-icon">
            <i class="glyph flaticon-011-sunny"></i>
          </div>
          <div class="weather-temp">
            <h1 id="current-temp">???</h1>
            <h3>???</h3>
            <span class="btn-group">
              <button type="button" class="btn btn-active" id="btn-cels">°C</button>
              <button type="button" class="btn btn-inactive" id="btn-fahr">°F</button>
            </span>
          </div>
          <div class="ai ai-1">
            <i class="glyph-desc wi wi-humidity"></i>
            <h3>Humidity</h3>
          </div>
          <div class="ai ai-2">
            <i class="glyph-desc wi wi-strong-wind"></i>
            <h3>Wind</h3>
          </div>
          <div class="ai ai-3">
            <i class="glyph-desc wi wi-sunset"><br></i>
            <h3>Sunset</h3>
          </div>
          <div class="weather-description">
            <h3>???</h3>
          </div>

    </div>

  </div>

  <script
			  src="https://code.jquery.com/jquery-3.3.1.min.js"
			  integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
			  crossorigin="anonymous">
  </script>
  <script src="assets/scripts.js"></script>

</body>

</html>

            
          
!
            
              /* html and all general styling */

*, *:before, *:after {
  box-sizing: inherit;
}

html {
  box-sizing: border-box;
  overflow-y: scroll;
  scroll-behavior: smooth;
}

body{
  font-family: 'Roboto', sans-serif;
  height: 100vh;
  width: 100vw;
  background-color: #212121;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 56 28' width='56' height='28'%3E%3Cpath fill='%23757575' fill-opacity='0.4' d='M56 26v2h-7.75c2.3-1.27 4.94-2 7.75-2zm-26 2a2 2 0 1 0-4 0h-4.09A25.98 25.98 0 0 0 0 16v-2c.67 0 1.34.02 2 .07V14a2 2 0 0 0-2-2v-2a4 4 0 0 1 3.98 3.6 28.09 28.09 0 0 1 2.8-3.86A8 8 0 0 0 0 6V4a9.99 9.99 0 0 1 8.17 4.23c.94-.95 1.96-1.83 3.03-2.63A13.98 13.98 0 0 0 0 0h7.75c2 1.1 3.73 2.63 5.1 4.45 1.12-.72 2.3-1.37 3.53-1.93A20.1 20.1 0 0 0 14.28 0h2.7c.45.56.88 1.14 1.29 1.74 1.3-.48 2.63-.87 4-1.15-.11-.2-.23-.4-.36-.59H26v.07a28.4 28.4 0 0 1 4 0V0h4.09l-.37.59c1.38.28 2.72.67 4.01 1.15.4-.6.84-1.18 1.3-1.74h2.69a20.1 20.1 0 0 0-2.1 2.52c1.23.56 2.41 1.2 3.54 1.93A16.08 16.08 0 0 1 48.25 0H56c-4.58 0-8.65 2.2-11.2 5.6 1.07.8 2.09 1.68 3.03 2.63A9.99 9.99 0 0 1 56 4v2a8 8 0 0 0-6.77 3.74c1.03 1.2 1.97 2.5 2.79 3.86A4 4 0 0 1 56 10v2a2 2 0 0 0-2 2.07 28.4 28.4 0 0 1 2-.07v2c-9.2 0-17.3 4.78-21.91 12H30zM7.75 28H0v-2c2.81 0 5.46.73 7.75 2zM56 20v2c-5.6 0-10.65 2.3-14.28 6h-2.7c4.04-4.89 10.15-8 16.98-8zm-39.03 8h-2.69C10.65 24.3 5.6 22 0 22v-2c6.83 0 12.94 3.11 16.97 8zm15.01-.4a28.09 28.09 0 0 1 2.8-3.86 8 8 0 0 0-13.55 0c1.03 1.2 1.97 2.5 2.79 3.86a4 4 0 0 1 7.96 0zm14.29-11.86c1.3-.48 2.63-.87 4-1.15a25.99 25.99 0 0 0-44.55 0c1.38.28 2.72.67 4.01 1.15a21.98 21.98 0 0 1 36.54 0zm-5.43 2.71c1.13-.72 2.3-1.37 3.54-1.93a19.98 19.98 0 0 0-32.76 0c1.23.56 2.41 1.2 3.54 1.93a15.98 15.98 0 0 1 25.68 0zm-4.67 3.78c.94-.95 1.96-1.83 3.03-2.63a13.98 13.98 0 0 0-22.4 0c1.07.8 2.09 1.68 3.03 2.63a9.99 9.99 0 0 1 16.34 0z'%3E%3C/path%3E%3C/svg%3E");
}

h1,h2,h3,h4,h5,h6{
  margin: 0px;
}

h1{
  font-size: 3em;
}

h2{
  font-size: 2em;
}

h3{
  font-size: 1.5em;
}

button {
  text-decoration: none;
  border: none;
}

button:focus {
  text-decoration: none;
}

/* wrapper styling */

.page-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  width: 100%;
}

.wrapper {
  display: grid;
  width: 500px;
  height: 500px;
  margin: auto;
  align-items: center;
  justify-content: center;
  opacity: 0.93;
  border-radius: 10px;
  background-color: #727272;
  color: #FFF;
  grid-template-columns: repeat(5, 100px);
  grid-template-rows: repeat(5, 100px);
  grid-template-areas:
    "la la la la la"
    ". wi wi wt ."
    ". wi wi wt ."
    ". ai1 ai2 ai3 ."
    "wd wd wd wd wd";
}

/* location area styling */

.location-area {
  display: flex;
  flex-direction: column;
  grid-area: la;
  align-items: center;
  justify-content: center;
}

/* weather icon styling */

.weather-icon {
  display: flex;
  grid-area: wi;
  align-items: center;
  justify-content: center;
}

.glyph:before {
  font-size: 7em;
}

/* weather temp styling */

.weather-temp {
  display: flex;
  flex-direction: column;
  grid-area: wt;
  justify-content: center;
  align-items: center;
}

/* button styling */

.btn {
  padding: 5px 10px;
  font-family: 'Roboto', sans-serif;
  font-size: 1em;
}

.btn-active {
  transition: background-color 0.3s ease;
  border: 2px solid #B3E5FC;
  background-color: #03A9F4;
  color: white;
}

.btn-inactive {
  transition: background-color 0.3s ease;
  background-color: #CFD8DC;
  color: white;
}

.btn-inactive:hover {
  border: 1px solid #03A9F4;
  background-color: #B3E5FC;
}

/* additional info styling */

.ai {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.ai > h3 {
  text-align: center;
  margin-top: 5px;
}

.ai-1 {
  grid-area: ai1;
  color: #B3E5FC;
}

.ai-2 {
  grid-area: ai2;
  color: #F5F5F5;
}

.ai-3 {
  grid-area: ai3;
  color: #FFCCBC;
}

.glyph-desc:before{
  font-size: 3em;
}

/* weather description styling */

.weather-description {
  grid-area: wd;
  display: flex;
  align-items: center;
  justify-content: center;
}


/*
 mobile responsvie styling
*/

@media (max-width: 600px) {

  body {
    margin: 0;
  }

  .page-container {
    margin: 0;
  }

  .wrapper{
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(5, 20vh);
    grid-template-areas:
      "la la la"
      "wi wi wt"
      "wi wi wt"
      "ai1 ai2 ai3"
      "wd wd wd";
    height: 100vh;
    width: 100vw;
    border-radius: 0px;
    margin: 0;
    opacity: 0.80;
  }

  .weather-temp {
    justify-content: center;
    align-items: flex-start;
  }

  .location-area > h3 {
    margin-top: 15px;
  }


}

@media (max-height: 400px) {

  .ai{
    display: none;
  }

  .wrapper{
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(4, 25vh);
    grid-template-areas:
      "la la la"
      "wi wi wt"
      "wi wi wt"
      "wd wd wd";
  }
  
}
            
          
!
            
              $(document).ready(function(){

  //check that geolocation is enabled in browser
  if ("geolocation" in navigator) {
    navigator.geolocation.getCurrentPosition(showPosition);
  //alert user if geolocation not enabled
  } else {
    alert("Please turn on geolocation in your browser options");
  }

  //declare showposition function to get users lon and location
  function showPosition(position){
    //declare lon and lat and api vars for readability
    const lon = position.coords.longitude;
    const lat = position.coords.latitude;
    let api = "https://fcc-weather-api.glitch.me/api/current?lat=" + lat + "&lon=" + lon;

    //make getjson call to fcc weather api to fetch weather data
    $.getJSON(api, function(data){

      console.log(data);
      //update location temp and desciption areas
      $(".location-area h2").text(data.name + ", " + data.sys.country);
      $(".weather-temp h1").text(Math.floor(data.main.temp));
      $(".weather-temp h3").text(data.weather[0].main);
      $(".ai-1 h3").text(data.main.humidity + "%");
      $(".ai-2 h3").text(data.wind.speed + " mi/h");
      $(".weather-description h3").text("~ " + data.weather[0].description + " ~");

      //make date object for displaying current date and time
      function updateDateTime(){
        let date = new Date();
        let hours = date.getHours();
        let minutes = "0" + date.getMinutes();
        let currDay = date.getDate();
        let currMonth = date.getMonth() + 1;
        let currYear = date.getFullYear();
        $(".location-area h3").text(hours + ":" + minutes.substr(-2) + "    " + currDay + "/" + currMonth + "/" + currYear);
      }
      updateDateTime();
      // set an interval to call function after 1 min to update time
      setInterval(updateDateTime, 1000);

      //make new date object to get formatted time for sunset / sunrise
      let sunsetTime = new Date(data.sys.sunset*1000);
      let sunsetHours = sunsetTime.getHours();
      let sunsetMinutes = "0" + sunsetTime.getMinutes();
      $(".ai-3 h3").text(sunsetHours + ":" + sunsetMinutes.substr(-2));

      // convert C to F when fahrenheit button clicked
      let currentTemp = $("#current-temp").text();
      $("#btn-fahr").click(function(){
        if ( $("#btn-fahr").hasClass("btn-inactive") ){
          $("#btn-fahr").toggleClass("btn-inactive btn-active");
          $("#btn-cels").toggleClass("btn-active btn-inactive");
          $("#current-temp").text( Math.floor( (parseInt(currentTemp) * 1.8) + 32) );
        }
      });
      //convert F to C when celsius button clicked
      $("#btn-cels").click(function(){
        $("#btn-fahr").toggleClass("btn-active btn-inactive");
        $("#btn-cels").toggleClass("btn-inactive btn-active");
        $("#current-temp").text( currentTemp );
      });

      // make switch statement to update weather icon
      switch (data.weather[0].main) {
        case 'Clear':
          $(".weather-icon").html("<i class='glyph wi wi-day-sunny'></i>");
          break;
        case 'Clouds':
          $(".weather-icon").html("<i class='glyph wi wi-day-cloudy'></i>");
          break;
        case 'Rain':
        case 'Drizzle':
          $(".weather-icon").html("<i class='glyph wi wi-rain-wind'></i>");
          break;
        case 'Thunderstorm':
          $(".weather-icon").html("<i class='glyph wi wi-thunderstorm' style='font-size: 7em'></i>");
          break;
        case 'Snow':
          $(".weather-icon").html("<i class='glyph wi wi-snow' style='font-size: 7em'></i>");
          break;
        case 'Atmosphere':
          $(".weather-icon").html("<i class='glyph wi wi-fog'></i>");
          break;
        case 'Extreme':
          $(".weather-icon").html("<i class='glyph wi wi-storm-warning'></i>");
          break;
        case 'Additional':
          $(".weather-icon").html('<i class="glyph flaticon-002-wind"></i>');
          break;
        default: $(".weather-icon").html('<i class="glyph flaticon-011-sunny"></i>');
      }

    });
  }




});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console