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

              
                <head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>

<body>
  <div class="container">
  <h4 class="appName">Weather App</h4>
  <h4 id="date_and_time"></h3>
  <h2 id="position"></h2><hr/>
  </div>  
  <div class="tabs">
    <div class="tab1 circles" style="margin-right: 90px; cursor: pointer;"><p id="temp"></p></div>
    <div class="tab2 circles" style="margin-left: 90px;"><p id="condition"></p></div>
    
  </div>  
  <div><footer>Local weather app. Coded by Milos Ratkovic for freeCodeCamp challenge using <a href="https://openweathermap.org/">OpenWeather</a> API. Click on temperature to switch between &degF/&degC.</footer></div>
</body>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Russo+One');

* {
  margin: 0;
  padding: 0;
}
.appName{
  bottom: 25px;
  left: 25px;
  color: black;
  position: absolute;
  font-family: 'Russo one';
  padding: 13px;
  background-color: rgba(255,255,255,0.4);
  border-radius: 20px;
  box-shadow : 0px 0px 80px 8px #000;
}
#date_and_time {
  position: absolute;
  bottom: 25px;
  right: 25px;
  background-color: rgba(255,255,255,0.5);
  font-family: 'Russo one';
  padding: 8px;
  border-radius: 20px;
  box-shadow : 0px 0px 80px 8px #000;
}
#position {
  text-align: center;
  font-family: 'Russo one';
  background-color: rgba(255,255,255,0.5);
  width: 55%;
  margin: 30px auto 0 auto;
  box-shadow : 0px 0px 80px 8px #000;
  border-radius: 20px;
  padding: 3px;
}
.tabs {
  width: 100%;
  text-align: center;
  margin-top: 70px;
}
.circles {
  display: inline-block;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  padding: 52px 0;
  font-size: 30px;
  font-weight: bold;
  font-family: 'Russo one';
  background-color: rgba(255,255,255,0.6);
  box-shadow : 0px 0px 80px 8px #000;
}
hr {
  border: 0;
  height: 1px;
  background-image: linear-gradient(to right, rgba(255, 0, 0, 0), rgba(255, 0, 0, 0.75), rgba(255, 0, 0, 0));
}

footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: white;
  font-size: 13px;
  background-color: rgba(0,0,0, 1);
}
a {
  color: white;
  text-decoration: underline;
}
a:hover {
  
  text-decoration: none;
  color: white;
}
              
            
!

JS

              
                
var lat = "";
var lon = "";
var api = "";
var locationAddress = "";
var temperature = "";
var mainWeatherCondition = "";


navigator.geolocation.getCurrentPosition(function(position) {
		console.log(position.coords);
		lat = position.coords.latitude;
		lon = position.coords.longitude;
				
		api = "https://cors-anywhere.herokuapp.com/http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=51559d73bbfe0ae092ac6df0e0a6c788&units=metric";
    
    locationAddress = "https://maps.googleapis.com/maps/api/geocode/json?latlng="+ lat + "," + lon + "&sensor=true";
	
		$.getJSON(api, function(weather) {
				console.log(weather);
        temperature = Math.round(weather.main.temp);
        mainWeatherCondition = weather.weather[0].main;
		    $("#temp").html(temperature + "<sup>&#8451;</sup>");
        $("#condition").html(mainWeatherCondition);
        
       

           switch(mainWeatherCondition) {
   
            case "Thunderstorm":
               $("body")
                 .hide()
                 .css("background-image", "url(http://wallpapercave.com/wp/Nm2GXqi.jpg)")
                 .css("background-size", "cover")
                 .css("background-attachment", "fixed")
                 .css("background-repeat", "no-repeat")
                 .css("background-position", "center")
                 .show();
             break;
             case "Snow":
               $("body") 
                 .hide()
                 .css("background-image", "url(http://www.artsfon.com/pic/201501/1920x1080/artsfon.com-44203.jpg)")
                 .css("background-size", "cover")
                 .css("background-attachment", "fixed")
                 .css("background-repeat", "no-repeat")
                 .css("background-position", "center")
                 .show(); 
               break;
             case "Rain":
               $("body")
                    .hide()
                    .css("background-image", "url(http://livehdwallpaper.com/wp-content/uploads/2016/07/Drizzling-Weather-Wallpapers-HD-Pictures.jpg)")
                    .css("background-size", "cover")
                    .css("background-attachment", "fixed")
                    .css("background-repeat", "no-repeat")
                    .css("background-position", "center")
                    .show();
               break;
               case "Drizzle":
               $("body")
                    .hide()
                    .css("background-image", "url(https://images4.alphacoders.com/831/thumb-1920-83196.jpg)")
                    .css("background-size", "cover")
                    .css("background-attachment", "fixed")
                    .css("background-repeat", "no-repeat")
                    .css("background-position", "center")  
                    .show();
               break;
               case "Clouds":               
               $("body")
                    .hide()
                    .css("background-image", "url(http://www.wallpaperandphoto.com/wp-content/uploads/2016/01/stormy_weather_city-wallpaper-2560x1600.jpg)")
                    .css("background-size", "cover")
                    .css("background-attachment", "fixed")
                    .css("background-repeat", "no-repeat")
                    .css("background-position", "center")
                    .show();
               break;
               case "Clear":                
               if (h >= 17 || h < 5) {                 
               $("body")
                    .hide()
                    .css("background-image", "url(https://s-media-cache-ak0.pinimg.com/originals/c6/28/0e/c6280e8f909cdaa96f599f4b611e876c.jpg)")
                    .css("background-size", "cover")
                    .css("background-attachment", "fixed")
                    .css("background-repeat", "no-repeat")
                    .css("background-position", "center")
                    .show();
               }
               else {
                 
                 $("body")
                 .hide()
                 .css("background-image", "url(https://wallpaperscraft.com/image/city_street_car_sun_59469_3840x2160.jpg)")
                 .css("background-size", "cover")
                 .css("background-attachment", "fixed")
                 .css("background-repeat", "no-repeat")
                 .css("background-position", "center") 
                 .show();
               }
               break;
               
               case "Mist":
               $("body")
                    .hide()
                    .css("background-image", "url(https://hdimagesnew.com/wp-content/uploads/2015/11/1447418203_Fog-HD-Wallpapers.jpg)")
                    .css("background-size", "cover")
                    .css("background-attachment", "fixed")
                    .css("background-repeat", "no-repeat")
                    .css("background-position", "center")
                    .show();
               break;
               case "Fog":
               $("body")
                    .hide()
                    .css("background-image", "url(https://hdimagesnew.com/wp-content/uploads/2015/11/1447418203_Fog-HD-Wallpapers.jpg)")
                    .css("background-size", "cover")
                    .css("background-attachment", "fixed")
                    .css("background-repeat", "no-repeat")
                    .css("background-position", "center")
                    .show();
               break;
           }
         

    });
    $.getJSON(locationAddress, function(data) {
					$("#position").html("<i class='fa fa-map-marker' style='color: red'></i>" + " " + data.results[1].formatted_address);
		      });
  
           
  
     });
	
  $(".tab1").click(function() {
          var checkForC = $("sup").html();
          var signC = String.fromCharCode(8451);

       if (checkForC === signC) {
              var newTempF = Math.round(temperature * 9/5) + 32;
              $("#temp").html(newTempF + "<sup>&#8457;</sup>");
       }
       else {
              $("#temp").html(temperature + "<sup>&#8451;</sup>");
       }
         
  }); 
function updateTime() {
var d = new Date();
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];


if (d.getHours() < 10) {
  h = "0" + d.getHours();
}
else {
  h = d.getHours();
}
if (d.getMinutes() < 10) {
  m = "0" + d.getMinutes();
}
else {
  m = d.getMinutes();
}
if (d.getSeconds() < 10) {
  s = "0" + d.getSeconds();
}  
else {
  s = d.getSeconds();
}  
document.getElementById("date_and_time").innerHTML = days[d.getDay()] + ", " + d.getDate() + " " + months[d.getMonth()] + " " + d.getFullYear() +  " - " + h + ":" + m + ":" + s;
  
setTimeout(updateTime, 1000);
}

if (window.location.protocol !== 'https:') {
    //window.location.href = 'https://' + window.location.hostname + window.location.pathname;  <-- this is not allowed in codepen.
    console.log(window.location);
    alert("If the app is not responding and you're using Chrome, please make sure to append 'https://' at the very beginning of the link in order to make geoLocation work. Thank you!");
}
updateTime();

              
            
!
999px

Console