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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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>
    <div class="content well error">
        <h1 class="block-text-center engraved-text" style="padding-bottom: 15px; margin-bottom: -7px;">Your Local Weather</h1>
        <div id="temp-cel">Loading...</div>
        <div id="additional-description" style="padding-bottom: 15px;" class="col">Loading...</div>
        <img id="weather-img" style="margin: 0px; margin-top: -30px; padding: 0px;"></img>
        <div class="row" id="select-temperature-type">
            <div class="col-6">
                <button type="button" id="cel-to-fahr" style="float: right;">Fahrenheit</button>
            </div>
            <div class="col-1">
                <button type="button" id="fahr-to-cel" style="padding-left: 20px; padding-right: 20px;">Celsius</button>
            </div>
        </div>
    </div>
</div>
              
            
!

CSS

              
                html {
    overflow: scroll;
    overflow-x: hidden;
}

::-webkit-scrollbar {
    width: 0px;
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #FF0000;
}

body {
    margin: 0px;
    font-family: 'Open Sans', sans-serif;
    font-size: 4vmin;
    background-image: url("https://dl.dropboxusercontent.com/s/u1emw5tie8q9te0/Loading.jpg?dl=0");
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    height: 980px;
    width: 100%;
  
    opacity: 1.0;
    -webkit-transition: background 2s linear;
    -moz-transition: background 2s linear;
    -o-transition: background 2s linear;
    -ms-transition: background 2s linear;
    transition: background 2s linear;  
}

button {
    background-color: rgb(80, 80, 80);
    color: white;
    border-style: none;
    border-radius: 30px;
    padding: 10px;
}

button:focus {
  outline: none;
}

br {
    line-height: 10%;
}

h1 {
    font-size: 10vmin;
}

p {
    font-size: 7vmax;
}

.engraved-text {
    color: #333;
    text-shadow: 0px 1px 0px rgba(255, 255, 255, .5);
    font-weight: bold;
}

.well {
    background: rgba(255, 255, 255, 0.3);
    border-style: none;
    border-radius: 50px;
}

.parent-display-table {
    display: table;
    width: 100%;
    height: 100%;
}

.child-display-table {
    display: table-cell;
    vertical-align: middle;
    text-align: center;
}

.content {
    display: block;
    margin: auto;
    margin-top: 50px;
    width: 60%;
    text-align: center;
}

body.error h1,
body.error #temp-cel {
  color: #fff;
}

body.error #additional-description,
body.error #weather-img,
body.error #select-temperature-type  {
  display: none;
}

body.error {
  background-image: url('https://wallpaperaccess.com/full/3257343.jpg');
}

.btn-primary {}

.block-text-center {
    display: block;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
}

.col-centered {
    float: none;
    margin-left: auto;
    margin-right: auto;
}

#temp-cel {
    font-size: 5.5vmin;
    font-family: Monospace;
    font-weight: bold;
}
              
            
!

JS

              
                $(document).ready(function() {

    // Variables   
    var city = "";
    var region = "";
    var country = "";
    var tempCel;
    var weatherImg = "";
    var lat = "";
    var long = "";
    var mainDescription;
    var additionalDescription;

    // Functions 
    function toTitleCase(additionalDescription) {
        return additionalDescription.replace(/\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
    }
  
  function getWeather(location, retryCount) {
        var retryCount = retryCount || 0;
        lat = location.loc.substr(0, 7);
        long = location.loc.substr(8);

        //JSON call for weather      
        $.getJSON("https://fcc-weather-api.glitch.me/api/current?lat=" + lat + "&lon=" + long, function(weather) {

            // Free Code Campe API Limit Error Message
            // Free Code Camp has a limited amount of requests it can make and defaults to Shunzenji, Japan when it reaches that limit. The API is used by the entire FCC community.
            if (weather.name == "Shuzenji") {
              var body = document.body;
              
              // First time error message
              if (retryCount == 0) {
                body.classList.add("error");
              var errorMessage = '<div>Please wait while we load your the weather for your area.</div> <br>NOTE: The Free Code Camp API limit for API requests has been reached. The API limit is 60 requests a minute (for the entire Free Code Camp Community). This page will automatically retry the weather API every 1 second.';
              document.getElementById("temp-cel").innerHTML = errorMessage;
              } else {
                // Let user know request was retried
              document.getElementById("temp-cel").innerHTML += '<br> Request retried.';
              }

              retryCount ++;

              // Terminate script after 10 retries
              if (retryCount > 10) {
                var errorMessage = 'This script has requested weather automatically 10 times and is now being terminated. Please manually refresh the page to try again.';
                document.getElementById("temp-cel").innerHTML = errorMessage;
                return false;
              }
              // Retry request
              return setTimeout(getWeather.bind(this, location, retryCount), 1000);
            } else {
              // Remove error styles
              var body = document.body;
              if (body.classList.contains("error")) {
                body.classList.remove("error");
              }
            }

            tempCel = weather.main.temp;
            weatherImg = weather.weather[0].icon;
            mainDescription = weather.weather[0].main;
            additionalDescription = weather.weather[0].description;
            additionalDescription = toTitleCase(additionalDescription);
            var celsiusToFahrenheit = (tempCel * 1.8) + 32;

            document.getElementById("temp-cel").innerHTML = celsiusToFahrenheit.toFixed(1) + " F";
            document.getElementById("additional-description").innerHTML = additionalDescription;
            var img = document.getElementById("weather-img");
            img.src = weatherImg;
            var bgImg = document.getElementsByTagName("body")[0];

            //Change background image based on temperature   
            // Hot  
            if (tempCel >= 27) {
                bgImg.style.backgroundImage = 'url("https://dl.dropboxusercontent.com/s/csi9wprlkodfl5n/Hot.jpg?dl=0")';            
            }

            // Temperate  
            else if (tempCel > 10 && tempCel < 27) {
                bgImg.style.backgroundImage = 'url("https://dl.dropboxusercontent.com/s/8e4vexh6x6fk2xr/Temperate.jpg?dl=0")';
            }

            // Cold  
            else {
                bgImg.style.backgroundImage = 'url("https://dl.dropboxusercontent.com/s/mnvnidvk6k4is2q/Cold.jpg?dl=0")';    
            }

            // Fahr to Cel Buttons
            $("#fahr-to-cel").click(function() {
                var tempConversion = document.getElementById("temp-cel");
                tempConversion.innerHTML = tempCel.toFixed(1) + " C";
                $("#cel-to-fahr").click(function() {
                    tempConversion.innerHTML = celsiusToFahrenheit.toFixed(1) + " F";
                });
            });
        });
    }

    $.getJSON("https://ipinfo.io/?callback=", getWeather);
});
              
            
!
999px

Console