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

              
                <section id="header">
	<div class="container">
		<header>
			<h1>freeCodeCamp: Local Weather App</h1>
		</header>
	</div><!-- .container -->
</section><!-- #localWeather -->

<section id="localWeather">
	<div class="container">
		<div class="row">
			<div class="col-md-4 offset-sm-3">
				<h3>Your Weather</h3>
			</div><!-- .col-sm-4 offset-sm-3 -->
		</div><!-- .row -->
		<div class="row">
			<div class="col-md-4 offset-sm-3">
				<div id="location">
					Location placeholder
				</div>
				<div id="weatherDesc">
					Desc
				</div>
				<div id="tempContainer">
						<span id="temp">Temp</span> &#176;<a id="scale" href="#scale">F</a>
				</div><!-- #temp -->
			</div><!-- .col-sm-8 offset-sm-3 -->
			<div class="col-sm-4">
				<img id="weatherIcon" src="" />
			</div><!-- .col-sm-4 -->
		</div><!-- .row -->
	</div><!-- .container -->
</section><!-- #localWeather -->

<section id="footer">
	<footer>a pen by <a href="https://jerkeller.com">Jer Keller</a></footer>
</section><!-- #footer -->
              
            
!

CSS

              
                body {
	color: #ccc;
	background: #0a0a0a;
	padding: 0 15px;
}

/* #### LAYOUT #### */
section {
	max-width: 800px;
	text-align: center;
	margin: 0 auto;
}

#header {
	margin: 30px auto 60px;
}

#localWeather {
	text-align: left;
}

#location {
	font-size: 1.4rem;
}

#weatherDesc {
	font-size: 1.1rem;
}

#temp, #scale {
	text-align: center;
}

#tempContainer {
	font-size: 1.4rem;
	font-weight: normal;
}

#scale:hover {
	text-decoration: none;
}

#footer {
	margin-top: 60px;
}

/* 768 */
/* #### MEDIA QUERIES #### */
@media screen and (max-width: 768px) {
	#weatherIcon {
		margin-left: 128px;
	}
}

/* 575 */
/* #### MEDIA QUERIES #### */
@media screen and (max-width: 575px) {
	#localWeather, #weatherIcon {
		text-align: center;
	}
	
	#weatherIcon {
		margin: 0 auto;
	}
}
              
            
!

JS

              
                // LOAD GETLOCATION FUNCTION
window.onfocus = function getLocation () {
	if ("geolocation" in navigator) {
		// GET USER'S GEO LOCATION USING HTML GEOLOCATION API
		function geo_success(position) {
			console.log("Success");
			// GET LATITUDE AND LONGITUDE
			var coord = {
				latitude: position.coords.latitude,
				longitude: position.coords.longitude
			};
			// MAKE API CALL
				var xhttp = new XMLHttpRequest();
				xhttp.onreadystatechange = function() {
						if (this.readyState == 4 && this.status == 200) {
							var jsonArray = JSON.parse(this.responseText);

							// USE RETURNED JSON DATA TO UPDATE THE DOM
							// UPDATE CITY AND COUNTRY
							document.getElementById("location").innerHTML = jsonArray.name + ", " + jsonArray.sys.country;
						// UPDATE ICON
							document.getElementById("weatherIcon").src = jsonArray.weather[0].icon;

						// UPDATE WEATHER DESCRIPTION
							// CAPITALIZE FIRST LETTER
							var firstLetter = jsonArray.weather[0].description.slice(0, 1).toUpperCase();
							// COLLECT TEXT FROM SECOND PART OF STRING
							var otherText = jsonArray.weather[0].description.slice(1);
							// CONCATENATE FIRST LETTER AND REST OF STRING
							var weatherDesc = firstLetter + otherText;
							document.getElementById("weatherDesc").innerHTML = weatherDesc;

						// TEMPERATURE VARIABLES
							var tempC = Math.round(jsonArray.main.temp);
							var tempF = Math.round(tempC * 9/5 + 32);
							// UPDATE TEMPERATURE: DEFAULT TO FAHRENHEIT
							document.getElementById("temp").innerHTML = tempF;

						// FUNCTION TO CHANGE SCALE FROM F TO C
							var tempToggle = document.getElementById("scale");

							tempToggle.addEventListener("click", function () {
								// TOGGLE
								if (document.getElementById("scale").innerHTML === "F") {
									document.getElementById("temp").innerHTML = tempC;
									document.getElementById("scale").innerHTML = "C";
								} else {
									document.getElementById("temp").innerHTML = tempF;
									document.getElementById("scale").innerHTML = "F";
								}
							});
						}
				};
				xhttp.open("GET", "https://fcc-weather-api.glitch.me/api/current?lat=" + coord.latitude + "&lon=" + coord.longitude, true);
				xhttp.send();
			}

		function geo_error() {
			alert("Sorry, no position available.");
		}

		var geo_options = {
			enableHighAccuracy: true, 
			maximumAge        : 30000, 
			timeout           : 27000
		};

		return navigator.geolocation.getCurrentPosition(geo_success, geo_error, geo_options);
	} else {
		alert("Geolocation is not supported by this browser");
	}

}
              
            
!
999px

Console