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

              
                <html>

<head>
   <meta charset="UTF-8" />
   <script src="https://use.fontawesome.com/5005443bc1.js"></script>
   <title>Local Weather</title>
</head>

<body id="body-block">
   <div class="bg-image">
      <div id="main-div" class="info">
         <div class="hidden-false"></div>
         <div id="locationName"></div>
         <div id="dateTime"></div>

         <div class="container">
            <div class="row">
               <div class="col-sm-4 col-side">
                  <div id="pressure"></div>
               </div>
               <div class="col-sm-4">
                  <div id="weatherDescription"></div>
                  <div id="weatherIcon">
                     <img src="#" alt="" id="icon-png" />
                  </div>
               </div>
               <div class="col-sm-4 col-side">
                  <div id="windData"></div>
               </div>
            </div>
         </div>

         <div id="tempCelcius"></div>
         <div id="btn-div"><a href="#" id="changeTemp" class="btn btn-default btn-sm">Farenheit</a></div>
         
      </div>
   </div>
   <footer>
      <p><a href="https://www.freecodecamp.com/zhann1982" target="_blank">@Zhann1982 </a></p>
   </footer>
</body>

</html>


              
            
!

CSS

              
                
@media only screen and (min-width: 1280px) {
   .info {display: block; margin: 150px  auto;}
}
@media only screen and (max-width: 1280px) {
   .info {display: block; margin: 100px auto;}
}
@media only screen and (max-width: 960px) {
   .info {display: block; margin: 60px auto;}
}
@media only screen and (max-width: 480px) {
   .info {display: block; margin: 30px auto;}
}

body {
   background-color: black;   
}

.hidden-false {
   display: none;
}

/* Button to change to Farenheit */
#changeTemp {
   background-color: green;
   color: #fff;
   text-decoration: none;
   font-weight: bold;
   margin-bottom: 30px;
   text-shadow: none;
   
}
#icon-png {
   height: 70px;
   width: 70px;
}

#locationName {
   font-size: 40px;
   font-weight: bold;
   text-align: center;
   margin-top: 25px;
   margin-bottom: 20px;
}

#dateTime {
   font-size: 30px;
   text-align: center;
}

#tempCelcius {
   font-size: 70px;
   text-align: center;
   margin-top: 30px;
   margin-bottom: 30px;
}

#btn-div {
   text-align: center;
      background-color:
}

.col-sm-4 {
   text-align: center;
   padding-top: 30px;
}

.col-side {
   
}

.info {
   
   background-color: rgba(0, 0, 0, 0.3);
   padding: 15px;
   border-radius: 20px;
   max-width: 800px;
   color: white;
}

footer p {
   text-align: center;
   color:white;
}

footer a {
   color:white;
   text-decoration: none;
}

footer a:hover {
   color:white;
   text-decoration: none;
}

footer a:focus {
   color:white;
   text-decoration: none;
}
              
            
!

JS

              
                $(document).ready(function() {
   document.getElementById("body-block").style.background = "url('http://www.publicdomainpictures.net/pictures/60000/velka/meadow-under-blue-sky.jpg') lightblue center no-repeat";
   var url, latNum, lonNum, tempDay;
   if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function(position) {
         latNum = Math.round(position.coords.latitude);
         lonNum = Math.round(position.coords.longitude);
         url = "https://cors-anywhere.herokuapp.com/http://api.openweathermap.org/data/2.5/weather?lat=" + latNum + "&lon=" + lonNum + "&appid=f8cdf8a56f5a52b67257c239fe0889f4&units=metric";
         var json = {};   
         $.getJSON(url, function(json) {
               tempDay = Math.round(json.main.temp);
            var locationName = json.name,
               latit = json.coord.lat,
               longi = json.coord.lon,
               weatherId = json.weather[0].id,
               weatherMain = json.weather[0].main, // main type of weather
               weatherDescription = json.weather[0].description, // description of type of weather
               weatherIcon = json.weather[0].icon, // look for icon in the list
               pressure = json.main.pressure,
               humidity = json.main.humidity,
               dateUnix = json.dt,
               windSpeed = Math.round(json.wind.speed),
               windDegree = json.wind.deg,
                 // formatting date and time
               date = new Date(dateUnix * 1000),
               dayDate = date.getDate(),
               monthNum = date.getMonth(),
               months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
               //hours = date.getHours(),
               //minutes = "0" + date.getMinutes(),
               //seconds = "0" + date.getSeconds(),
               formattedDateTime = months[monthNum] + " " + dayDate;
            $('#locationName').html(locationName);
            $('#dateTime').html(formattedDateTime);
            $('#tempCelcius').html('<i class="fa fa-fw fa-thermometer-half"></i> ' + tempDay + ' C&deg');
            $('#weatherDescription').html(weatherDescription);
            $('#weatherIcon').html('<img src="http://openweathermap.org/img/w/' + weatherIcon + '.png" alt="" id="icon-png" />');
            if (weatherIcon === "01d" || weatherIcon === "01n") {
               document.getElementById("body-block").style.background = "url('http://www.publicdomainpictures.net/pictures/60000/velka/meadow-under-blue-sky.jpg') lightblue center no-repeat";
            } 
            if (weatherIcon === "02d" || weatherIcon === "02n") {
               document.getElementById("body-block").style.background = "url('http://www.publicdomainpictures.net/pictures/100000/velka/clouds-in-blue-sky-14094113785iy.jpg') lightblue center no-repeat";
            }
            if (weatherIcon === "03d" || weatherIcon === "03n") {
               document.getElementById("body-block").style.background = "url('http://www.publicdomainpictures.net/pictures/190000/velka/blue-sky-1473075035JhZ.jpg') lightblue center no-repeat";
            }
            if (weatherIcon === "04d" || weatherIcon === "04n") {
               document.getElementById("body-block").style.background = "url('http://www.publicdomainpictures.net/pictures/60000/velka/sky-filled-with-heavy-clouds.jpg') lightblue center no-repeat";
            }
            if (weatherIcon === "10d" || weatherIcon === "10n") {
               document.getElementById("body-block").style.background = "url('http://www.publicdomainpictures.net/pictures/180000/velka/water-background-1467297923UJR.jpg') lightblue center no-repeat";
            }
            if (weatherIcon === "09d" || weatherIcon === "09n") {
               document.getElementById("body-block").style.background = "url('http://www.publicdomainpictures.net/pictures/180000/velka/water-drops-14672984924HY.jpg') lightblue center no-repeat";
            }
            if (weatherIcon === "11d" || weatherIcon === "11n") {
               document.getElementById("body-block").style.background = "url('http://www.publicdomainpictures.net/pictures/170000/velka/multiple-lightning-bolts.jpg') lightblue center no-repeat";
            }
            if (weatherIcon === "13d" || weatherIcon === "13n") {
               document.getElementById("body-block").style.background = "url('http://www.publicdomainpictures.net/pictures/70000/velka/snow-falling-1.jpg') lightblue center no-repeat";
            }
            if (weatherIcon === "50d" || weatherIcon === "50n") {
               document.getElementById("body-block").style.background = "url('http://www.publicdomainpictures.net/pictures/180000/velka/misty-14639358057oo.jpg') lightblue center no-repeat";
            }
            // formatting wind direction
            var windDir = "";
            if (windDegree >= 348.75 || windDegree < 11.25) {
               windDir = "North";
            };
            if (windDegree >= 326.25 || windDegree < 348.75) {
               windDir = "North-North-West";
            };
            if (windDegree >= 303.75 || windDegree < 326.25) {
               windDir = "North-West";
            };
            if (windDegree >= 281.25 || windDegree < 303.75) {
               windDir = "West-North-West";
            };
            if (windDegree >= 258.75 || windDegree < 281.25) {
               windDir = "West";
            };
            if (windDegree >= 236.25 || windDegree < 258.75) {
               windDir = "West-South-West";
            };
            if (windDegree >= 213.75 || windDegree < 236.25) {
               windDir = "South-West";
            };
            if (windDegree >= 191.25 || windDegree < 213.75) {
               windDir = "South-South-West";
            }
            if (windDegree >= 168.75 || windDegree < 191.25) {
               windDir = "South";
            };
            if (windDegree >= 146.25 || windDegree < 168.75) {
               windDir = "South-South-East";
            };
            if (windDegree >= 123.75 || windDegree < 146.25) {
               windDir = "South-East";
            };
            if (windDegree >= 101.25 || windDegree < 123.75) {
               windDir = "East-South-East";
            };
            if (windDegree >= 78.75 || windDegree < 101.25) {
               windDir = "East";
            };
            if (windDegree >= 56.25 || windDegree < 78.75) {
               windDir = "East-North-East";
            };
            if (windDegree >= 33.75 || windDegree < 56.25) {
               windDir = "North-East";
            };
            if (windDegree >= 11.25 || windDegree < 33.75) {
               windDir = "North-North-East";
            };
            $('#windData').html("Wind:  " + windSpeed + " m/s<br/ > " + windDir);
            var mmHg = Math.round(pressure*0.7500615613); 
            $('#pressure').html("ATM: " + mmHg + " mmHg<br/ >" + pressure + " hPa");
         }); /* end of getJSON */
      });  /* end of navigator.geolocation */
   } else {
      $("#locationName").html("Your geolocation information is not available.");
      $("#changeTemp").hide();
   } /* end of IF */
   
   $("#changeTemp").on("click", function() {     /* Button effects */
         var innerText = document.getElementById("changeTemp").innerHTML;
         if (innerText === "Farenheit") {
            var farenheitTemp = Math.round((tempDay*9/5) + 32);
            $('#tempCelcius').html('<i class="fa fa-fw fa-thermometer-half"></i> ' + farenheitTemp + ' F&deg');
            $('#changeTemp').html('Celsius');
         } else if (innerText === "Celsius") {
            $('#tempCelcius').html('<i class="fa fa-fw fa-thermometer-half"></i> ' + tempDay + ' C&deg');
            $('#changeTemp').html('Farenheit');       
         }
   }); /* Button effects */
}); /* end of document.ready*/

/*
01d - 01n - clear sky --  http://www.publicdomainpictures.net/pictures/60000/velka/meadow-under-blue-sky.jpg
02d - 02n - few clouds -- http://www.publicdomainpictures.net/pictures/100000/velka/clouds-in-blue-sky-14094113785iy.jpg
03d - 03n - scattered clouds -- http://www.publicdomainpictures.net/pictures/190000/velka/blue-sky-1473075035JhZ.jpg
04d - 04n - broken clouds -- http://www.publicdomainpictures.net/pictures/60000/velka/sky-filled-with-heavy-clouds.jpg
10d - 10n - rain -- http://www.publicdomainpictures.net/pictures/180000/velka/water-background-1467297923UJR.jpg
09d - 09n - shower rain -- http://www.publicdomainpictures.net/pictures/180000/velka/water-drops-14672984924HY.jpg
11d - 11n - thunderstorm -- http://www.publicdomainpictures.net/pictures/170000/velka/multiple-lightning-bolts.jpg
13d - 13n - snow -- http://www.publicdomainpictures.net/pictures/70000/velka/snow-falling-1.jpg
50d - 50n - mist -- http://www.publicdomainpictures.net/pictures/180000/velka/misty-14639358057oo.jpg
*/
              
            
!
999px

Console