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

              
                <div class="bg-layer">
  <div class="container current-info">
    <div>
      <h1 id="city-name"></h1>
      <h2>Today:</h2>
      <h2 class="temp-parts" id="temp-now"></h2>
      <h2 class="temp-parts measure"></h2>
      <p id="description"></p>
      <p id="humidity"> The Humidity is: </p>
      <button type="button" id="measure-cel">Celcius</button>
    </div>
  </div>

  <div class="container">
    <h2>For the Next Six Days:</h2>
    <h3 id="week-summary"></h3>
    <div class="row">
      <div class="col-sm-4">
        <h2 class="temp-parts" id="max-temp0"></h2>
         <h2 class="temp-parts measure"></h2>
        <p id="description0"></p>
        <p id="humidity0"></p>
      </div>
      <div class="col-sm-4">
        <h2 class="temp-parts" id="max-temp1"></h2>
         <h2 class="temp-parts measure"></h2>
        <p id="description1"></p>
        <p id="humidity1"></p>
      </div>
      <div class="col-sm-4">
        <h2 class="temp-parts" id="max-temp2"></h2>
         <h2 class="temp-parts measure"></h2>
        <p id="description2"></p>
        <p id="humidity2"></p>
      </div>
      <div class="col-sm-4">
        <h2 class="temp-parts" id="max-temp3"></h2>
         <h2 class="temp-parts measure"></h2>
        <p id="description3"></p>
        <p id="humidity3"></p>
      </div>
      <div class="col-sm-4">
        <h2 class="temp-parts" id="max-temp4"></h2>
         <h2 class="temp-parts measure"></h2>
        <p id="description4"></p>
        <p id="humidity4"></p>
      </div>
      <div class="col-sm-4">
        <h2 class="temp-parts" id="max-temp5"></h2>
         <h2 class="temp-parts measure"></h2>
        <p id="description5"></p>
        <p id="humidity5"></p>
      </div>
    </div>
    <div id="extender"></div>
  </div>
</div>
              
            
!

CSS

              
                body {
  background: no-repeat center center fixed;
  background-color: grey;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

h1,
h2,
h3,
h4,
p {
  color: white;
}

.bg-layer {
  width: 100vw;
  height: 100%;
  background-color: rgba(0, 0, 0, .2);
}

.current-info {
  width: 44%;
  display: table;
  margin: 0 auto;
  align-content: center;
  text-align: center;
  padding: 5px
}

.temp-parts {
  display: inline-block;
}

#city-name {
  margin-bottom: 50px;
}

#temp-now {
  margin: 0px 0px 30px 0px;
}

.col-sm-4 {
  background: rgba(0, 0, 0, .4);;
  height: auto;
  border-left: solid 1px;
  border-right: solid 2px;
  margin-top: 40px;
  min-height: 200px;
}

.container {
  text-align: center;
}

#extender {
  margin-top: 10%;
}
              
            
!

JS

              
                var farOrCel = "far";
// Sets up backgrounds to change with the local weather
var clearSky = "https://s27.postimg.org/8qyk7hvf7/cloud_1117279_1280.jpg";
var clouds = 'https://s29.postimg.org/yipb24vjb/sky_62732_1280.jpg';
var rain = "https://s29.postimg.org/eh756xw6f/rain_122691_1280.jpg";
var thunder = "https://s23.postimg.org/xuf19kv6z/lightning_399853_1280.jpg";
var snow = "https://s27.postimg.org/5x13r40jn/ortler_1449017_1280.jpg";
var mist = "https://s30.postimg.org/6o4q70n69/misty_1208267_1280.jpg";
//checks to see if the browser support gelocation
if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(function(position) {
    //holds on to values to use in API call

    var lat = position.coords.latitude;
    var long = position.coords.longitude;
    var weekApi = "https://api.forecast.io/forecast/43484630341eaa8e7cf87ace0f649063/";
    var weekApiFull = weekApi + lat + "," + long;
    $.ajax({
      url: weekApiFull,
      dataType: 'jsonp',
      method: 'GET',
      success: function(data) {
          // return data for manipulation

          return data;
        }
        //Summary/tempurature/description data output
    }).then(function(data) {
      var currentWeather = (data.hourly.summary).toLowerCase();
      console.log(currentWeather);
      if (currentWeather.indexOf("clear") != -1) {
        $('body').css('background-image', 'url("' + clearSky + '")');
      } else if (currentWeather.indexOf("cloud") != -1) {
        $('body').css('background-image', 'url("' + clouds + '")');
      } else if (currentWeather.indexOf("rain") != -1 || currentWeather.indexOf("drizzle") != -1) {
        $('body').css('background-image', 'url("' + rain + '")');
      } else if (currentWeather.indexOf("storm") != -1) {
        $('body').css('background-image', 'url("' + thunder + '")');
      } else if (currentWeather.indexOf("snow") != -1) {
        $('body').css('background-image', 'url("' + snow + '")');
      } else if (currentWeather.indexOf("mist") != -1 || currentWeather.indexOf("fog") != -1) {
        $('body').css('background-image', 'url("' + mist + '")');
      } else {
        $('body').css('background-image', 'url("' + clearSky + '")');
      }

      var humidity = data.hourly.data[0].humidity;
      $("#humidity").text("The Humidity is: " + humidity + "%");
      var description = currentWeather;
      $("#description").html(description);
      var cityName = data.name;
      $("#city-name").html(cityName);

      var tempNow = Math.round(data.hourly.data[0].temperature);
      console.log(tempNow);

      // assigned current temp to be changed to farenheit or cel
      var temp0Min = Math.round(data.daily.data[1].temperatureMin);
      var temp0Max = Math.round(data.daily.data[1].temperatureMax);
      var temp1Min = Math.round(data.daily.data[2].temperatureMin);
      var temp1Max = Math.round(data.daily.data[2].temperatureMax);
      var temp2Min = Math.round(data.daily.data[3].temperatureMin);
      var temp2Max = Math.round(data.daily.data[3].temperatureMax);
      var temp3Min = Math.round(data.daily.data[4].temperatureMin);
      var temp3Max = Math.round(data.daily.data[4].temperatureMax);
      var temp4Min = Math.round(data.daily.data[5].temperatureMin);
      var temp4Max = Math.round(data.daily.data[5].temperatureMax);
      var temp5Min = Math.round(data.daily.data[6].temperatureMin);
      var temp5Max = Math.round(data.daily.data[6].temperatureMax);
      // default Temp. Display: Farenhiet
      

      $("#measure-cel").click(function() {
        if(farOrCel == "far"){
          farOrCel = "cel";
          $("#measure-cel").text("Farenheit");
          $(".measure").text("℃");
          
          $("#temp-now").text(Math.round((tempNow - 32) /1.8));
          $("#max-temp0").html(Math.round((temp0Min - 32) /1.8) + " - " + Math.round((temp0Max- 32) /1.8));
          $("#max-temp1").html(Math.round((temp1Min - 32) /1.8) + " - " + Math.round((temp1Max- 32) /1.8));
          $("#max-temp2").html( Math.round((temp2Min - 32) /1.8) + " - " + Math.round((temp2Max - 32) /1.8));
          $("#max-temp3").html( Math.round((temp3Min - 32) /1.8) + " - " + Math.round((temp3Max - 32) /1.8));
          $("#max-temp4").html( Math.round((temp4Min - 32) /1.8) + " - " + Math.round((temp4Max - 32) /1.8));
          $("#max-temp5").html( Math.round((temp5Min - 32) /1.8) + " - " + Math.round((temp5Max - 32) /1.8));
      } else {
        $("#measure-cel").text("Celcius");
        farOrCel = "far";
        setFarenheit();
      }
      });
      var weekLongDescriptionArr = data.daily.summary.split(" ");
      var weekLongTemp = weekLongDescriptionArr.find(function(str) {return str.indexOf("°") != -1})
      weekLongTemp = weekLongTemp.slice(0, weekLongTemp.length - 2)
      $("#week-summary").text(data.daily.summary);
      
      function setFarenheit() {
      $("#temp-now").text(tempNow);
      $(".measure").text("℉");
      $("#max-temp0").html(temp0Min + " - " + temp0Max);
      $("#max-temp1").html(temp1Min + " - " + temp1Max);
      $("#max-temp2").html( temp2Min + " - " + temp2Max);
      $("#max-temp3").html( temp3Min + " - " + temp3Max);
      $("#max-temp4").html( temp4Min + " - " + temp4Max);
      $("#max-temp5").html( temp5Min + " - " + temp5Max);
      }
      
      setFarenheit();
      
      $("#description0").text(data.daily.data[1].summary);
      $("#description1").text(data.daily.data[2].summary);
      $("#description2").text(data.daily.data[3].summary);
      $("#description3").text(data.daily.data[4].summary);
      $("#description4").text(data.daily.data[5].summary);
      $("#description5").text(data.daily.data[6].summary);

      $("#humidity0").text("The Humidity will be: " +
        (Math.round(data.daily.data[1].humidity * 100)) + "%");
      $("#humidity1").text("The Humidity will be: " +
        (Math.round(data.daily.data[2].humidity * 100)) + "%");
      $("#humidity2").text("The Humidity will be: " +
        (Math.round(data.daily.data[3].humidity * 100)) + "%");
      $("#humidity3").text("The Humidity will be: " +
        (Math.round(data.daily.data[4].humidity * 100)) + "%");
      $("#humidity4").text("The Humidity will be: " +
        (Math.round(data.daily.data[5].humidity * 100)) + "%");
      $("#humidity5").text("The Humidity will be: " +
        (Math.round(data.daily.data[6].humidity * 100)) + "%");
    })
  });

} else {
  alert("Geolocation is unavailable in your browser. Try enabling it in your settings or accepting the prompt that may have been provided.")
}
              
            
!
999px

Console